Repository navigation
Fix JNI decompressor error messages for lz4 1.11.0 error codes - #176
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
lz4 1.11.0 (bumped in #172) changed
LZ4_decompress_safefailure returns from a position-encoded-(ip-src)-1to 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 alwayssrcOff + 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 offsetMalformed inputException type stays
LZ4Exception. No existing test or doc asserted the old message.LZ4JNIErrorTestuses 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 localverifypasses.🤖 Generated with Claude Code