{"record":{"id":"56113c841ac88948","repo":"aeron-io/aeron","slug":"invalid-key-length","errorCode":null,"errorMessage":"Invalid key length","messagePattern":"Invalid key length","errorType":"validation","errorClass":"InvalidMessage","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/logging/CborDecode.java","lineNumber":351,"sourceCode":"            state.incrementOffset(1 + length);\n        }\n        else if (ADDITIONAL_CONTENT_2_BYTE == keyAdditionalContent)\n        {\n            state.ensureRemaining(2);\n            final int length = 0xFFFF & state.buffer().getShort(state.offset(), BIG_ENDIAN);\n            targetBuffer.wrap(state.buffer(), state.offset() + 2, length);\n            state.incrementOffset(2 + length);\n        }\n        else if (ADDITIONAL_CONTENT_4_BYTE == keyAdditionalContent)\n        {\n            state.ensureRemaining(4);\n            final int length = state.buffer().getInt(state.offset(), BIG_ENDIAN);\n            targetBuffer.wrap(state.buffer(), state.offset() + 4, length);\n            state.incrementOffset(4 + length);\n        }\n        else\n        {\n            throw new InvalidMessage(\"Invalid key length\");\n        }\n    }\n\n    private void parseString(\n        final DecodingState state,\n        final AsciiSequenceView targetView,\n        final int keyAdditionalContent)\n    {\n        if (keyAdditionalContent < ADDITIONAL_CONTENT_1_BYTE)\n        {\n            targetView.wrap(state.buffer(), state.offset(), keyAdditionalContent);\n            state.incrementOffset(keyAdditionalContent);\n        }\n        else if (ADDITIONAL_CONTENT_1_BYTE == keyAdditionalContent)\n        {\n            state.ensureRemaining(1);\n            final int length = 0xFF & state.buffer().getByte(state.offset());\n            targetView.wrap(state.buffer(), state.offset() + 1, length);","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/logging/CborDecode.java#L333-L369","documentation":"parseByteArray in CborDecode validates that a CBOR byte-string key has one of the supported length encodings before wrapping the target buffer. When the length header does not match the supported widths (e.g. an 8-byte length header where only shorter forms are expected, or a corrupt byte), it throws 'Invalid key length'.","triggerScenarios":"Decoding an event entry whose map key is a byte string with an unexpected length header; a misaligned buffer offset causes a non-length byte to be read as the length header.","commonSituations":"Corrupted or truncated Aeron event-log captures; decoding logs written by a different Aeron version; off-by-one buffer slicing before parseEntry.","solutions":["Confirm the decode offset points at the start of the CBOR key, not mid-payload.","Re-capture the event log with the same Aeron version used to decode it.","Check the source buffer for truncation/corruption.","Compare the captured binary against a known-good log to locate the divergent byte."],"exampleFix":"// before\nelse\n{\n    throw new InvalidMessage(\"Invalid key length\");\n}\n// after\nelse\n{\n    throw new InvalidMessage(\"Invalid key length: additionalContent=\" + additionalContent(keyTypeByte));\n}","handlingStrategy":"try-catch","validationCode":"// ensure declared byte-string length fits in remaining buffer before parsing\nfinal int headerByte = buffer.getByte(offset) & 0xFF;\nfinal int majorType = (headerByte & 0xE0) >> 5;\nfinal int info = headerByte & 0b000_11111;\nif (majorType != 2) { /* not a byte string */ }","typeGuard":"boolean isByteStringKey(final byte headerByte)\n{\n    final int majorType = (headerByte & 0xE0) >> 5;\n    final int info = headerByte & 0b000_11111;\n    return majorType == 2 && (info < 24 || info == 24 || info == 25 || info == 26);\n}","tryCatchPattern":"try\n{\n    cborDecoder.decode(buffer, offset, limit);\n}\ncatch (final InvalidMessage ex)\n{\n    LOGGER.warn(\"invalid CBOR key encoding at \" + offset + \", skipping record\");\n}","preventionTips":["Decode from verified record boundaries only.","Keep capture tooling and decoder versions aligned.","Sanity-check declared lengths against remaining() before wrapping buffers.","Fail-soft per record: catch InvalidMessage and continue scanning."],"tags":["cbor","decoding","serialization"],"backgroundTag":"invalid-argument-format","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"}