Skip to content

compress: support high dictionary IDs on 32-bit builds - #4864

Draft
trestoncuzzort wants to merge 1 commit into
facebook:devfrom
trestoncuzzort:fix-high-dict-id
Draft

trestoncuzzort wants to merge 1 commit into
facebook:devfrom
trestoncuzzort:fix-high-dict-id

Conversation

@trestoncuzzort

Copy link
Copy Markdown

What and why

Fixes #4580.

On 32-bit builds, dictionary IDs near UINT32_MAX overlap the encoded size_t error range. The compression-side dictionary loaders returned either an ID or an error, so a valid dictionary could fail with Error (generic) or make ZSTD_createCDict() return NULL. These high IDs are permitted for private use.

The internal loaders now return status and write the U32 ID separately. The public API stays the same, and the ID is preserved in the compressed frame.

Validation

  • The new regression fails on the original 32-bit code. It checks direct dictionaries, prepared CDicts and CCtx-loaded dictionaries with four IDs, verifies the frame ID, and checks the decoded bytes.
  • Fixed 32-bit and 64-bit basic suites and 100 seeded randomized iterations pass on each.
  • Fork CI: 101 build/test jobs passed with all non-workflow files identical to this patch. Fork-only runner/compiler adjustments address unavailable gold/qemu packages, historical-build compatibility, a PowerPC runtime mismatch and existing Clang 23 warnings. Original test commands, flags, durations and size limits were retained.
  • The fork's three original OSS-Fuzz jobs used upstream source after a failed PR fetch, so I excluded those results. The replacement run built this exact commit with source-hash checks: all 21 targets completed under address, undefined and memory sanitizers, with the original 600-second budget per job. Changed-file filtering was unavailable, so all targets ran. Five public corpus downloads returned 403; those targets still ran, and the warnings are retained in the logs.
  • Matched size comparison: base and fix have identical ELF file sizes in all four configurations. With that toolchain, both exceed the ordinary-build limit; the other three limits pass.

Local static analysis is not clean. Clang 23 reports the same 15 diagnostic/source signatures on base and fix; a Clang 18 comparison reports the same nine on both. Neither comparison passes. I am submitting this as a draft with that baseline limitation explicit.

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: not applicable; no performance gain is claimed.
  • I stated below whether AI or other automated tools were used.

Tools used

OpenAI Codex (GPT-6) assisted with investigation, implementation and tests. dawnr checked a mathematical model of status encoding; that model does not prove the C implementation.

ZSTD_loadZstdDictionary() and ZSTD_compress_insertDictionary() returned
both dictionary IDs and errors through size_t. On 32-bit builds, valid
private dictionary IDs near UINT32_MAX overlap the encoded error range
and are rejected by their callers.

Return a status and write the ID through an output parameter instead.
Raw or absent dictionaries still produce ID zero, and failed loads still
return their error before the caller stores the ID.

Add round trips and frame-ID checks for low and high IDs through direct
dictionaries, prepared CDicts, and CCtx-loaded dictionaries.
@meta-cla

meta-cla Bot commented Oct 26, 2026

Copy link
Copy Markdown

Hi @trestoncuzzort!

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 commented Oct 26, 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!

@meta-cla meta-cla Bot added the CLA Signed label Oct 26, 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.

Dictionary ID can't >= 4294967177 in 32-bit build

1 participant