Repository navigation
seekable_format: Reject offsets past the end in decompress - #4902
Open
eyupcanakman wants to merge 1 commit into
Open
eyupcanakman wants to merge 1 commit into
eyupcanakman wants to merge 1 commit into
Conversation
ZSTD_seekable_decompress() limited len with offset + len > eos. An offset well past the end made eos - offset underflow into a huge byte count that ZSTD_isError() did not flag. An offset + len that wrapped around skipped the limit, and the loop never exited. Return parameter_outOfBound for an offset past the end, and compare len against eos - offset. Reading at the end still returns 0.
This branch has not been deployed
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.
What and why
ZSTD_seekable_decompress()limitslenwithif (offset + len > eos) len = eos - offset;, and two kinds of input get past it.When
offsetis past the end of the data,eos - offsetunderflows. On a 1000-byte stream, reading 16 bytes at offset 5000 returns 18446744073709547616, andZSTD_isError()reports it as a success. Whenoffset + lenwraps around, the limit is skipped and the decompress loop never exits.The fix returns
parameter_outOfBoundfor an offset past the end and compareslenagainsteos - offsetinstead. Reading at exactly the end still returns 0.The new Test 6 in
seekable_tests.cfails without the fix.Checklist
A gain in one configuration is not a general gain: see the Performance section of CONTRIBUTING.md.
Tools used
Claude Code found the bug and wrote the fix and the test.