{"record":{"id":"9773ba8c3b6a892d","repo":"aeron-io/aeron","slug":"length-overflow","errorCode":null,"errorMessage":"length overflow: ","messagePattern":"length overflow: ","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/DirectBufferVector.java","lineNumber":188,"sourceCode":"    }\n\n    /**\n     * Validate an array of vectors to make up a message and compute the total length.\n     *\n     * @param vectors to be validated summed.\n     * @return the sum of the vector lengths.\n     */\n    public static int validateAndComputeLength(final DirectBufferVector[] vectors)\n    {\n        int messageLength = 0;\n        for (final DirectBufferVector vector : vectors)\n        {\n            vector.validate();\n            messageLength += vector.length;\n\n            if (messageLength < 0)\n            {\n                throw new IllegalStateException(\"length overflow: \" + Arrays.toString(vectors));\n            }\n        }\n\n        return messageLength;\n    }\n}\n","sourceCodeStart":170,"sourceCodeEnd":195,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/DirectBufferVector.java#L170-L195","documentation":"validateAndComputeLength() sums the lengths of all vectors and throws IllegalStateException when the running total becomes negative, which can only happen through int overflow — the combined vector data exceeds Integer.MAX_VALUE (2GB). Aeron throws this because a message length cannot be represented as a positive int for the vectored write protocol.","triggerScenarios":"Calling a vectored publish/offer with enough vectors that sum(vectors[i].length) exceeds Integer.MAX_VALUE, causing int overflow to a negative value. Requires very large individual vectors or an enormous number of vectors.","commonSituations":"Batching many large messages into a single vectored write without a size budget; a bug where lengths are double-counted in an accumulation loop; passing the same large buffer repeatedly in the vector array.","solutions":["Cap total batch size: accumulate lengths yourself and split the vector array into multiple sends before exceeding Integer.MAX_VALUE.","Reduce per-vector lengths; send oversized payloads in chunks via multiple publications.","Audit the loop that builds the vectors for double-counting of length values."],"exampleFix":"// before\noffer(vectors); // may overflow int\n// after\nlong total = 0;\nint split = 0;\nfor (int i = 0; i < vectors.length; i++) {\n    total += vectors[i].length;\n    if (total > Integer.MAX_VALUE) { offer(Arrays.copyOfRange(vectors, split, i)); split = i; total = vectors[i].length; }\n}","handlingStrategy":"validation","validationCode":"long total = 0;\nfor (DirectBufferVector v : vectors) { total += v.length; }\nif (total > Integer.MAX_VALUE) { throw new IllegalArgumentException(\"batch too large: \" + total); }","typeGuard":"null","tryCatchPattern":"try {\n    publication.offer(vectors);\n} catch (IllegalStateException e) {\n    log.error(\"vector batch exceeds 2GB int limit\", e);\n    splitAndResend(vectors);\n}","preventionTips":["Track a running long total when assembling vector batches and split before Integer.MAX_VALUE.","Never include the same large buffer twice in one vector array.","Keep per-publication batch size well under 2GB by policy."],"tags":["aeron","buffer-vector","integer-overflow","message-size-limit"],"backgroundTag":"payload-too-large","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}