Skip to content

seekable_format: Reject offsets past the end in decompress - #4902

Merged
Cyan4973 merged 2 commits into
meta:devfrom
eyupcanakman:seekable-decompress-past-end
Nov 9, 2026
Merged

Cyan4973 merged 2 commits into
meta:devfrom
eyupcanakman:seekable-decompress-past-end

Conversation

@eyupcanakman

Copy link
Copy Markdown
Contributor

What and why

ZSTD_seekable_decompress() limits len with if (offset + len > eos) len = eos - offset;, and two kinds of input get past it.

When offset is past the end of the data, eos - offset underflows. On a 1000-byte stream, reading 16 bytes at offset 5000 returns 18446744073709547616, and ZSTD_isError() reports it as a success. When offset + len wraps around, the limit is skipped and the decompress loop never exits.

The fix returns parameter_outOfBound for an offset past the end and compares len against eos - offset instead. Reading at exactly the end still returns 0.

The new Test 6 in seekable_tests.c fails without the fix.

Checklist

  • I searched open pull requests and issues: this problem is not already being addressed.
  • Bug fix: it comes with a reproducer or a test that fails without the fix.
  • Performance change: numbers from repeated runs are included, with CPU, compiler, flags and data.
    A gain in one configuration is not a general gain: see the Performance section of CONTRIBUTING.md.
  • I stated below whether AI or other automated tools were used.

Tools used

Claude Code found the bug and wrote the fix and the test.

@meta-cla meta-cla Bot added the CLA Signed label Nov 6, 2026
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
eyupcanakman force-pushed the seekable-decompress-past-end branch from d0b3725 to f9c9c68 Compare November 9, 2026 11:43
@Cyan4973 Cyan4973 self-assigned this Nov 9, 2026
@Cyan4973 Cyan4973 added the bug label Nov 9, 2026
…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 Cyan4973 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

Just added a commit documenting the return value in these limit scenarios.

@Cyan4973
Cyan4973 merged commit e6bd22d into meta:dev Nov 9, 2026
105 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants