Repository navigation
Fix COVER_selectDict() stale customDictContentEnd (heap OOB read) - #4821
Open
ceedot-rock wants to merge 1 commit into
Open
ceedot-rock wants to merge 1 commit into
ceedot-rock wants to merge 1 commit into
Conversation
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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