{"record":{"id":"61cf990c5732a3ae","repo":"aeron-io/aeron","slug":"lengthtwo-0-lengthtwo","errorCode":null,"errorMessage":"lengthTwo < 0: {lengthTwo}","messagePattern":"lengthTwo < 0: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/Publication.java","lineNumber":726,"sourceCode":"    final void checkMaxMessageLength(final int length)\n    {\n        if (length > maxMessageLength)\n        {\n            throw new IllegalArgumentException(\n                \"message exceeds maxMessageLength of \" + maxMessageLength + \", length=\" + length);\n        }\n    }\n\n    static int validateAndComputeLength(final int lengthOne, final int lengthTwo)\n    {\n        if (lengthOne < 0)\n        {\n            throw new IllegalArgumentException(\"lengthOne < 0: \" + lengthOne);\n        }\n\n        if (lengthTwo < 0)\n        {\n            throw new IllegalArgumentException(\"lengthTwo < 0: \" + lengthTwo);\n        }\n\n        final int totalLength = lengthOne + lengthTwo;\n        if (totalLength < 0)\n        {\n            throw new IllegalArgumentException(\"overflow totalLength=\" + totalLength);\n        }\n\n        return totalLength;\n    }\n\n    /**\n     * Returns a string representation of a position. Generally used for errors. If the position is a valid error then\n     * String name of the error will be returned. If the value is 0 or greater the text will be \"NONE\". If the position\n     * is negative, but not a known error code then \"UNKNOWN\" will be returned.\n     *\n     * @param position position value returned from a call to offer.\n     * @return String representation of the error.","sourceCodeStart":708,"sourceCodeEnd":744,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/Publication.java#L708-L744","documentation":"Thrown by Publication.validateAndComputeLength when lengthTwo is negative in a vectored (two-buffer) offer. The helper checks both component lengths before summing them, so the second buffer's length must also be non-negative.","triggerScenarios":"publication.offer(bufferOne, offsetOne, lengthOne, bufferTwo, offsetTwo, lengthTwo) with lengthTwo < 0 — commonly a negative remaining() on the second buffer or a miscomputed payload length.","commonSituations":"Header+payload sends where the payload buffer wasn't flipped; deserialized length fields applied directly as buffer lengths; slicing errors producing inverted offsets on the second buffer.","solutions":["Validate lengthTwo >= 0 before the vectored offer call.","Ensure the second buffer is in read mode (flip() after writes) before computing its length.","Add boundary assertions where the two lengths are derived so negative values cannot reach offer()."],"exampleFix":"// before\nint bodyLen = bodyEnd - bodyStart; // negative when bodyStart > bodyEnd\npublication.offer(header, 0, headerLen, body, 0, bodyLen);\n\n// after\nint bodyLen = bodyEnd - bodyStart;\nif (bodyLen < 0)\n{\n    throw new IllegalArgumentException(\"invalid body length: \" + bodyLen);\n}\npublication.offer(header, 0, headerLen, body, 0, bodyLen);","handlingStrategy":"validation","validationCode":"if (lengthTwo < 0) { throw new IllegalArgumentException(\"second buffer length must be >= 0, got \" + lengthTwo); }","typeGuard":"boolean isValidSecondLength(int lengthTwo) { return lengthTwo >= 0; }","tryCatchPattern":"try\n{\n    publication.offer(buf1, off1, len1, buf2, off2, len2);\n}\ncatch (IllegalArgumentException e)\n{\n    // negative lengthTwo: correct the payload buffer sizing logic\n    log.error(\"invalid vectored offer\", e);\n}","preventionTips":["Flip the payload buffer before measuring; un-flipped buffers yield negative remaining().","Assert slice boundaries (start <= end) where the second length is derived.","Validate decoded/wire lengths before using them as buffer lengths.","Keep vectored length computation in tested utility methods."],"tags":["aeron","publication","vectored-offer","argument-validation"],"backgroundTag":"invalid-argument-value","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"}