Skip to content

fuzz: check ZSTD_decompressBound() against declared sizes - #4832

Open
ilyas-mallah wants to merge 1 commit into
meta:devfrom
ilyas-mallah:decompress-bound-upper-bound
Open

ilyas-mallah wants to merge 1 commit into
meta:devfrom
ilyas-mallah:decompress-bound-upper-bound

Conversation

@ilyas-mallah

@ilyas-mallah ilyas-mallah commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The zstd_frame_info fuzz target now asserts that ZSTD_decompressBound() equals ZSTD_findDecompressedSize() when every frame declares its size. An overflowing total must be an error for both. The two functions answer the same question for such input, so the check catches either one drifting.

Legacy frames are skipped through a new helper, FUZZ_isCurrentFormat(), because the frozen legacy decoders ignore the declared size.

I ran zstd_frame_info with ASan and UBSan on a saved corpus for 120 s (3,684,427 runs), and it found no failure.

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.
  • I stated below whether AI or other automated tools were used.

Tools used

AI usage: Claude Code helped with the fuzzing runs and test builds. I traced the problem, wrote the check, and validated every change.

@meta-cla

meta-cla Bot commented Oct 9, 2026

Copy link
Copy Markdown

Hi @ilyas-mallah!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed label Oct 9, 2026
@meta-cla

meta-cla Bot commented Oct 9, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@ilyas-mallah

Copy link
Copy Markdown
Contributor Author

@terrelln @Cyan4973 The open question in the description: should single-pass decoding reject Raw and RLE blocks above Block_Maximum_Size (#4669), instead of the bound counting them? I kept them decodable because rejecting changes which inputs decode. I can rework it to reject if you'd rather. Could one of you also approve the workflow run? No CI has run here or on #4833 and #4834, two small separate fixes (zstd -l and ZSTD_frameHeaderSize()). dev hasn't moved since I opened them, so nothing needs a rebase.

@ilyas-mallah

Copy link
Copy Markdown
Contributor Author

@Cyan4973 @terrelln Two small separate fixes wait only on the first workflow approval: #4833 (zstd -l hang on a large skippable frame) and #4834 (ZSTD_frameHeaderSize for skippable frames). Neither depends on #4832 or the other. Could one of you approve the run and say if either needs a change?

@ilyas-mallah ilyas-mallah changed the title decompress: make ZSTD_decompressBound() a true upper bound decompress: return an error from ZSTD_decompressBound() on overflow Nov 10, 2026
@ilyas-mallah

Copy link
Copy Markdown
Contributor Author

@terrelln @Cyan4973 I pushed 688fe83, which drops the Raw and RLE part now that 75aeac4 rejects oversized blocks. Only the overflow guard is left. CI now runs on #4832. Could #4834 get a run too? Closing and reopening did it for #4833.

@ilyas-mallah ilyas-mallah changed the title decompress: return an error from ZSTD_decompressBound() on overflow fuzz: check ZSTD_decompressBound() against declared sizes Nov 15, 2026
@ilyas-mallah

Copy link
Copy Markdown
Contributor Author

@terrelln 6404711 already makes ZSTD_decompressBound() return an error on overflow and adds its own test, so I edited this PR down to what dev doesn't have. The library change and my unit test are gone. What's left is a zstd_frame_info fuzz check that the bound equals ZSTD_findDecompressedSize() when every frame declares its size, with legacy frames skipped. On dev before that commit the check fails on a two-frame input declaring 2^63 bytes each, where the bound was 0. I updated the title and description to match.

@terrelln terrelln 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 PR @ilyas-mallah! Sorry we ended up merging parallel fixes while this was outstanding.

@terrelln

Copy link
Copy Markdown
Contributor

This PR will need to be rebased before merging.

Assert bound == ZSTD_findDecompressedSize() when every frame declares its size. Legacy frames are skipped through FUZZ_isCurrentFormat() since the frozen legacy decoders ignore the declared size.
@ilyas-mallah
ilyas-mallah force-pushed the decompress-bound-upper-bound branch from 7db4f8a to d0bf1a1 Compare November 18, 2026 21:22

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.

2 participants