Repository navigation
seekable_format: Reject offsets past the end in decompress - #4902
Merged
Merged
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.
eyupcanakman
force-pushed
the
seekable-decompress-past-end
branch
from
November 9, 2026 11:43
d0b3725 to
f9c9c68
Compare
…e data The return value is smaller than dstSize when the data ends first, 0 when offset is the end of the data, and an error past it.
Cyan4973
approved these changes
Nov 9, 2026
Cyan4973
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the fix!
Just added a commit documenting the return value in these limit scenarios.
3 of 4 tasks
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.