aeron-io/aeron · error · InvalidMessage

Invalid key length

Error message

Invalid key length

What it means

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'.

Solutions

  1. Confirm the decode offset points at the start of the CBOR key, not mid-payload.
  2. Re-capture the event log with the same Aeron version used to decode it.
  3. Check the source buffer for truncation/corruption.
  4. Compare the captured binary against a known-good log to locate the divergent byte.

Example fix

// before
else
{
    throw new InvalidMessage("Invalid key length");
}
// after
else
{
    throw new InvalidMessage("Invalid key length: additionalContent=" + additionalContent(keyTypeByte));
}
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure declared byte-string length fits in remaining buffer before parsing
final int headerByte = buffer.getByte(offset) & 0xFF;
final int majorType = (headerByte & 0xE0) >> 5;
final int info = headerByte & 0b000_11111;
if (majorType != 2) { /* not a byte string */ }

Type guard

boolean isByteStringKey(final byte headerByte)
{
    final int majorType = (headerByte & 0xE0) >> 5;
    final int info = headerByte & 0b000_11111;
    return majorType == 2 && (info < 24 || info == 24 || info == 25 || info == 26);
}

Try / catch

try
{
    cborDecoder.decode(buffer, offset, limit);
}
catch (final InvalidMessage ex)
{
    LOGGER.warn("invalid CBOR key encoding at " + offset + ", skipping record");
}

Prevention

When it happens

Trigger: 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.

Common situations: Corrupted or truncated Aeron event-log captures; decoding logs written by a different Aeron version; off-by-one buffer slicing before parseEntry.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of aeron-io/aeron@6d60124e15 (2026-09-12). Data as JSON: /api/errors/56113c841ac88948. Report an issue: GitHub.

Appendix: source

Thrown at aeron-client/src/main/java/io/aeron/logging/CborDecode.java:351

            state.incrementOffset(1 + length);
        }
        else if (ADDITIONAL_CONTENT_2_BYTE == keyAdditionalContent)
        {
            state.ensureRemaining(2);
            final int length = 0xFFFF & state.buffer().getShort(state.offset(), BIG_ENDIAN);
            targetBuffer.wrap(state.buffer(), state.offset() + 2, length);
            state.incrementOffset(2 + length);
        }
        else if (ADDITIONAL_CONTENT_4_BYTE == keyAdditionalContent)
        {
            state.ensureRemaining(4);
            final int length = state.buffer().getInt(state.offset(), BIG_ENDIAN);
            targetBuffer.wrap(state.buffer(), state.offset() + 4, length);
            state.incrementOffset(4 + length);
        }
        else
        {
            throw new InvalidMessage("Invalid key length");
        }
    }

    private void parseString(
        final DecodingState state,
        final AsciiSequenceView targetView,
        final int keyAdditionalContent)
    {
        if (keyAdditionalContent < ADDITIONAL_CONTENT_1_BYTE)
        {
            targetView.wrap(state.buffer(), state.offset(), keyAdditionalContent);
            state.incrementOffset(keyAdditionalContent);
        }
        else if (ADDITIONAL_CONTENT_1_BYTE == keyAdditionalContent)
        {
            state.ensureRemaining(1);
            final int length = 0xFF & state.buffer().getByte(state.offset());
            targetView.wrap(state.buffer(), state.offset() + 1, length);

View on GitHub (pinned to 6d60124e15)