Repository navigation
fix(c-api): refuse a decompression bound the result cannot carry - #668
Conversation
- ZSTD_decompressBound returned a total of exactly u64::MAX as it was, which reads as ZSTD_CONTENTSIZE_UNKNOWN, a value this function never returns; a single frame declaring that size did the same. The largest bound returned is now ZSTD_CONTENTSIZE_ERROR - 1 and anything at or past the sentinels is ZSTD_CONTENTSIZE_ERROR, the boundary upstream closes in meta/zstd#4954. - The sum over frames moves into the codec as decoding::decompressed_bound (the whole of u64 is a bound there, a sum past it an overflow), so the C ABI only maps the result onto its sentinels. - A frame's on-disk length and its bound come from one walk of its blocks; the bound of a run of frames walked each frame twice. - Regression tests: the boundary cases of upstream's test_decompressBoundOverflow through the C ABI, the same boundary with a v0.5 to v0.7 frame as the tail, and the codec's sum. Closes #663
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 52 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb467b7abc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The sums over concatenated frames step by each frame's on-disk length, which is at least its header and ends inside the buffer. The C ABI loop this replaced tested that at run time; the walk guarantees it, so the test stays as a debug assertion in both sums. Part of #663
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
## 🤖 New release * `structured-zstd`: 0.3.0 -> 0.4.0 <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [0.4.0](v0.3.0...v0.4.0) - 2026-11-14 ### Added - *(decoding)* [**breaking**] hold dictionary content in the caller's buffer ([#649](#649)) - *(encode)* let the caller choose how a frame uses a dictionary ([#641](#641)) ### Fixed - *(c-api)* refuse a decompression bound the result cannot carry ([#668](#668)) ### Performance - *(encode)* one dictionary index per dictionary for attached and copied frames ([#662](#662)) - *(decoding)* decode small frames' long matches without libc memcpy ([#658](#658)) - *(encode)* trim dfast tail seeding and the optimal parser's per-node work ([#656](#656)) - *(encode)* one page fault per table page on a fresh workspace ([#655](#655)) - *(decoding)* close the x86 decode gap to libzstd ([#652](#652)) ### Testing - *(bench)* measure ours with and without the raw skip ([#644](#644)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). Co-authored-by: sw-release-bot[bot] <255865126+sw-release-bot[bot]@users.noreply.github.com>
Summary
ZSTD_decompressBoundreturns a number below its sentinels orZSTD_CONTENTSIZE_ERROR. A total of exactlyu64::MAX(or a single frame declaring that size) used to come back as is, which reads asZSTD_CONTENTSIZE_UNKNOWN, a value this function never returns. The largest bound returned isZSTD_CONTENTSIZE_ERROR - 1, the boundary upstream closes in decompress: reject unrepresentable decompression bounds meta/zstd#4954.Changes
decoding::decompressed_bound: the bound of every frame in a buffer together, skippable frames counting zero. The whole ofu64is a bound there; a sum past it isDecompressedSizeError::Overflow, a damaged frame or stray bytes after the last one that frame's error.ZSTD_decompressBoundcalls it and returnsZSTD_CONTENTSIZE_ERRORfor any total at or above that value.find_frame_compressed_sizeandframe_decompressed_boundshare it); bounding a run of frames walked each frame twice.u64::MAXis an error here. Upstream treats that field value as undeclared and returns the block bound; its regression only requires that the result is notZSTD_CONTENTSIZE_UNKNOWN.Testing
test_decompressBoundOverflowthrough the C ABI, the same boundary with a v0.5 to v0.7 frame as the tail, and the codec's sum; the first failed before the fix.legacyfeature, clippy, formatting, the no_std check and the doc example pass on aarch64; the full suite and the platform matrix run in CI.Closes #663
Summary by CodeRabbit