Skip to content

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

Open
eyupcanakman wants to merge 1 commit into
meta:devfrom
eyupcanakman:seekable-decompress-past-end
Open

eyupcanakman wants to merge 1 commit 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.

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.
@meta-cla meta-cla Bot added the CLA Signed label Nov 6, 2026

This branch has not been deployed

No deployments
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.

1 participant