{"record":{"id":"166a30b862c2aa2c","repo":"aeron-io/aeron","slug":"invalid-input-capturelength-capturelength-length-length","errorCode":null,"errorMessage":"invalid input: captureLength=${captureLength}, length=${length}","messagePattern":"invalid input: captureLength=(.+?), length=(.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/logging/CommonEventEncoder.java","lineNumber":80,"sourceCode":"     * @param length         original length.\n     * @return header length in bytes.\n     */\n    public static int encodeLogHeader(\n        final MutableDirectBuffer encodingBuffer, final int offset, final int captureLength, final int length)\n    {\n        return internalEncodeLogHeader(encodingBuffer, offset, captureLength, length, SystemNanoClock.INSTANCE);\n    }\n\n    static int internalEncodeLogHeader(\n        final MutableDirectBuffer encodingBuffer,\n        final int offset,\n        final int captureLength,\n        final int length,\n        final NanoClock nanoClock)\n    {\n        if (captureLength < 0 || captureLength > length || captureLength > MAX_CAPTURE_LENGTH)\n        {\n            throw new IllegalArgumentException(\"invalid input: captureLength=\" + captureLength + \", length=\" + length);\n        }\n\n        int encodedLength = 0;\n        /*\n         * Stream of values:\n         * - capture buffer length (int)\n         * - total buffer length (int)\n         * - timestamp (long)\n         * - buffer (until end)\n         */\n\n        encodingBuffer.putInt(offset + encodedLength, captureLength, LITTLE_ENDIAN);\n        encodedLength += SIZE_OF_INT;\n\n        encodingBuffer.putInt(offset + encodedLength, length, LITTLE_ENDIAN);\n        encodedLength += SIZE_OF_INT;\n\n        encodingBuffer.putLong(offset + encodedLength, nanoClock.nanoTime(), LITTLE_ENDIAN);","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/logging/CommonEventEncoder.java#L62-L98","documentation":"CommonEventEncoder.internalEncodeLogHeader validates the capture-length parameters before writing an event-log header. captureLength must be non-negative, no greater than the full record length, and no greater than MAX_CAPTURE_LENGTH. Passing any value outside that range throws IllegalArgumentException, meaning the caller computed an invalid capture size.","triggerScenarios":"Calling encodeLogHeader with captureLength < 0; captureLength exceeding the record length; captureLength exceeding MAX_CAPTURE_LENGTH (e.g. passing the full buffer length when it exceeds the capture cap).","commonSituations":"Custom event logger implementations computing min() incorrectly; misconfigured capture-length system properties; passing buffer capacity instead of record length.","solutions":["Clamp captureLength: Math.min(length, MAX_CAPTURE_LENGTH) and ensure >= 0 before calling encodeLogHeader.","Check the configuration/source of captureLength (often a system property) for a bad value.","Ensure length reflects the actual encoded record size, not buffer capacity.","Guard the caller with a validation step and skip logging when invalid."],"exampleFix":"// before\nencoder.encodeLogHeader(buffer, captureLength, length, clock); // captureLength may exceed length\n// after\nfinal int safeCapture = Math.min(Math.max(captureLength, 0), Math.min(length, CommonEventEncoder.MAX_CAPTURE_LENGTH));\nencoder.encodeLogHeader(buffer, safeCapture, length, clock);","handlingStrategy":"validation","validationCode":"static boolean isValidCaptureParams(final int captureLength, final int length)\n{\n    return captureLength >= 0\n        && captureLength <= length\n        && captureLength <= CommonEventEncoder.MAX_CAPTURE_LENGTH;\n}\n// call encodeLogHeader only if isValidCaptureParams(captureLength, length)","typeGuard":null,"tryCatchPattern":"try\n{\n    CommonEventEncoder.encodeLogHeader(buffer, captureLength, length, clock);\n}\ncatch (final IllegalArgumentException ex)\n{\n    LOGGER.error(\"bad log header params\", ex);\n}","preventionTips":["Always clamp captureLength to min(length, MAX_CAPTURE_LENGTH) before encoding.","Never pass buffer capacity as record length.","Validate captureLength config sources (system properties) at startup.","Add an assert on the invariant captureLength <= length in custom loggers."],"tags":["logging","argument-validation"],"backgroundTag":"argument-out-of-range","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}