Repository navigation
Validate maxCompressedLength overflow and stream array ranges (#671, #513) - #741
Merged
Merged
Conversation
- maxCompressedLength: throw SnappyError(TOO_LARGE_INPUT) instead of returning a negative size when the result overflows int, and reject negative input sizes (#671) - Snappy.arrayCopy: check both ranges before the native memcpy, which SnappyOutputStream.rawWrite and SnappyInputStream.rawRead rely on - SnappyOutputStream.write / SnappyInputStream.read: validate offset and length against the array, and reject typed-array ranges whose byte offset overflows int (#513) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 3, 2026
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.
Summary
Snappy.maxCompressedLength(n)returned a negative number for n ≥ 1,840,700,243, because the native result32 + n + n/6overflowsint. It now throwsSnappyError(TOO_LARGE_INPUT), and a negativenthrowsIllegalArgumentException. This also replaces the privaterequiredCompressedLengthhelper added in Fix buffer overflows and unbounded allocations from untrusted input (CVE-2026-90559 and others) #739.Snappy.arrayCopy: it ran a nativememcpywith no bounds check, soSnappyOutputStream.rawWrite(new int[4], 0, 1024)read past the array andSnappyInputStream.rawReadcould write past it. Both ranges are now checked first.SnappyOutputStream.write(...)andSnappyInputStream.read(...)forbyte[]and typed arrays now checkoff/lenagainst the array length (IndexOutOfBoundsException). For typed arrays, a byte offsetoff * elementSizethat overflowsintis rejected; before, it could wrap around to a wrong in-range offset.Test plan
SnappyBoundsCheckTest, including the exact overflow boundary 1,840,700,242 / 1,840,700,243./sbt test: 133 passed🤖 Generated with Claude Code