Skip to content

Fix COVER_selectDict() stale customDictContentEnd (heap OOB read) - #4821

Open
ceedot-rock wants to merge 1 commit into
meta:devfrom
ceedot-rock:dict-bug-4750
Open

ceedot-rock wants to merge 1 commit into
meta:devfrom
ceedot-rock:dict-bug-4750

Conversation

@ceedot-rock

Copy link
Copy Markdown

Fixes #4750.

In COVER_selectDict() (lib/dictBuilder/cover.c), customDictContentEnd is computed from the input content size S0, but the shrinkDict trial loop is bounded by largestDict, the finalized dictionary size S1 (about S0+154). Any tried size in (S0, S1) underflows the content buffer, and ZDICT_finalizeDictionary() then reads out of bounds in XXH64 (zdict.c:883).

The fix is one line plus a comment: bound the trial loop by the content size instead of the finalized size.

Reproducer (tests/test-cover-selectdict-stale.c, sweeps sizes 240-2000): fails 3/3 pre-fix under ASan with a deterministic heap-buffer-overflow READ, passes post-fix, ASan/UBSan clean. Existing dictBuilder tests (169, 170, 172, 174 incl. shrinkDict) and 200 fuzzer iterations pass with zero failures. fastcover.c doesn't share the pattern - untouched.


Slid Phi Labs accepts donations to keep the lab independent.

Slid Phi Labs accepts donations to keep the lab independent: https://www.patreon.com/SlidPhiLabs

COVER_selectDict() computed customDictContentEnd from the input content
size, then let ZDICT_finalizeDictionary() overwrite dictContentSize with
the larger finalized size (content + header). The shrinkDict loop used
that finalized size as its bound while passing
customDictContentEnd - dictContentSize as candidate content, so a tried
size between the content size and the finalized size made the pointer
underflow the content buffer (heap-buffer-overflow read).

Bound the loop by the content size instead. Adds a reproducer test that
sweeps content sizes through COVER_selectDict with shrinkDict enabled.
@meta-cla meta-cla Bot added the CLA Signed label Oct 4, 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.

COVER_selectDict() uses stale customDictContentEnd after ZDICT_finalizeDictionary modifies dictContentSize

1 participant