Skip to content

Fix JNI decompressor error messages for lz4 1.11.0 error codes - #176

Merged
yawkat merged 1 commit into
mainfrom
claude/jni-error-codes-1-11-73fc43
Nov 7, 2026
Merged

yawkat merged 1 commit into
mainfrom
claude/jni-error-codes-1-11-73fc43

Conversation

@yawkat

@yawkat yawkat commented Nov 7, 2026

Copy link
Copy Markdown
Owner

lz4 1.11.0 (bumped in #172) changed LZ4_decompress_safe failure returns from a position-encoded -(ip-src)-1 to fixed error codes (lz4 commit b67d3f51):

  • -1: malformed/truncated input
  • -2: output doesn't fit into the destination (or corrupted input)
  • -3: match offset points before the start of the output (or corrupted input)

The JNI wrappers still computed "Error decoding offset " + (srcOff - result) + " of input buffer", so the reported offset was always srcOff + 1..3. LZ4_decompress_fast (LZ4_decompress_unsafe_generic) only ever returns -1, so its message was already meaningless. The JNI C glue passes results through unchanged.

This maps the codes to messages without a position:

  • -2 → Malformed input or destination buffer too small
  • -3 → Malformed input: invalid match offset
  • otherwise → Malformed input

Exception type stays LZ4Exception. No existing test or doc asserted the old message.

LZ4JNIErrorTest uses small crafted blocks, checks that the raw native call returns exactly -1/-2/-3, and asserts the messages for the JNI safe decompressor (byte[] and direct ByteBuffer, with a non-zero srcOff) and the JNI fast decompressor (nativeInsecureInstance). Full local verify passes.

🤖 Generated with Claude Code

Since lz4 1.11.0, LZ4_decompress_safe returns fixed error codes (-1
malformed input, -2 destination too small, -3 invalid offset) instead of
-(position)-1, so "Error decoding offset N of input buffer" always
reported srcOff+1..3. LZ4_decompress_fast only ever returns -1, so its
position was meaningless as well. Map the codes to messages that don't
claim a position.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yawkat
yawkat enabled auto-merge (squash) November 7, 2026 11:39
@yawkat
yawkat merged commit 8b92a01 into main Nov 7, 2026
3 checks passed
@yawkat
yawkat deleted the claude/jni-error-codes-1-11-73fc43 branch November 7, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant