Repository navigation
Throw LZ4Exception for input shorter than the length prefix - #160
Merged
Merged
Conversation
LZ4DecompressorWithLength read the 4-byte length prefix without checking that the input is long enough, so input of fewer than 4 bytes surfaced as ArrayIndexOutOfBoundsException, IndexOutOfBoundsException or IllegalArgumentException instead of LZ4Exception. Check the available compressed length in all decompress overloads, for both fast and safe decompressors, before reading the prefix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yawkat
added a commit
that referenced
this pull request
Oct 15, 2026
Place it after destinationBufferLimitsDecompressedLength so that it does not conflict with the short input test from #160. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yawkat
marked this pull request as ready for review
October 15, 2026 13:21
yawkat
added a commit
that referenced
this pull request
Oct 15, 2026
…fer, int) (#161) * Use the buffer limit for the safe decompress(ByteBuffer, int, ByteBuffer, int) With a safe decompressor, decompress(ByteBuffer src, int srcOff, ByteBuffer dest, int destOff) computed the compressed length as src.remaining() - srcOff, mixing the buffer's position with the absolute offset. Valid input failed to decompress whenever src.position() was not 0. Use src.limit() - srcOff, which matches the absolute indexing of the other ByteBuffer arguments and the fast path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Move the ByteBuffer source offset test Place it after destinationBufferLimitsDecompressedLength so that it does not conflict with the short input test from #160. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- 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.
LZ4DecompressorWithLengthread the 4-byte length prefix without checking that the input was long enough. Input with fewer than 4 bytes therefore failed with anArrayIndexOutOfBoundsExceptionorIndexOutOfBoundsExceptioninstead of the documentedLZ4Exception. Examples:On the safe paths with an explicit
srcLen < 4inside a longer array, the prefix was read pastsrcLen, and the call then failed with anIllegalArgumentExceptionfor the negative remaining length.All
decompressoverloads now check that at least 4 bytes are available before reading the prefix, and throwLZ4Exceptionif they aren't. This covers array andByteBuffer, and fast and safe decompressors. The available length issrcLenfor the safe paths,src.length - srcOfforsrc.limit() - srcOfffor the fast paths, andsrc.remaining()fordecompress(ByteBuffer, ByteBuffer). Invalid offsets still throwArrayIndexOutOfBoundsException, as before. The public staticgetDecompressedLengthhelpers are unchanged.Found by fuzzing with micronaut-fuzzing.
Tests: I added
OutOfBoundsTest.inputShorterThanLengthPrefixfor 0–3 byte inputs. It runs every overload with fast and safe decompressors, using heap and direct buffers. I also addedsafeInputShorterThanLengthPrefixWithTrailingBytes, which coverssrcLen < 4inside a longer array or buffer. Without the fix, all three test cases fail with AIOOBE or IAE. With the fix,OutOfBoundsTestandLZ4Testpass.🤖 Generated with Claude Code