Repository navigation
Fix stream buffer double release, header recursion, and eager chunk allocation - #747
Merged
Merged
Conversation
…llocation - SnappyFramedInputStream: clear released buffer fields before allocating replacements, so close() does not release them to the pool again when the allocation fails, which let two streams share one buffer - SnappyInputStream: skip concatenated stream headers in a loop instead of recursing once per 16-byte header - SnappyInputStream: grow the compressed chunk buffer as data arrives instead of allocating the declared chunk size (up to 512 MiB) from a 4-byte header - Document that the raw memory address APIs cannot check bounds 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.
Summary
Fixes the issues from the private security reports that 1.1.10.9 didn't cover.
SnappyFramedInputStream.ensureBuffer()andallocateBuffersBasedOnSize()returned buffers to the pool before allocating their replacements. If the allocation threw (e.g.OutOfMemoryError), the fields still pointed at the released buffers, andclose()released them again.CachingBufferPooldoesn't detect duplicates, so two later streams could get the same backing array. The fields are now cleared immediately after release.SnappyInputStream.hasNextChunk(). Each header of a concatenated stream recursed once, so a long run of 16-byte headers overflowed the stack. Headers are now skipped in a loop, the same pattern as snappy-java through 1.1.10.8 Uncontrolled Recursion via SnappyFramedInputStream skippable chunks #731.SnappyInputStream. The compressed-chunk buffer was allocated at the declaredchunkSize(up to the 512 MiBMAX_CHUNK_SIZE) before any chunk data was read, so a truncated stream of a few bytes could force a 512 MiB allocation. The buffer now starts at 64 KiB, or the chunk size if smaller, and doubles as data arrives. The uncompressed-buffer allocation is already bounded by the size check added in Fix buffer overflows and unbounded allocations from untrusted input (CVE-2026-90559 and others) #739.rawCompress(long, long, long)andrawUncompress(long, long, long)take no destination capacity, so they can't be bounds-checked. Their Javadoc now marks them unsafe, says what the caller must check, and points to the bounds-checkedByteBufferoverloads.Test plan
SnappyBoundsCheckTest, all of which fail without the fix:./sbt test: 139 passed🤖 Generated with Claude Code