Fix issue T283341343 - #4731
Open
Cyan4973 wants to merge 3 commits into
Open
Conversation
Bug: ZSTD_DDictHashSet_getDDict and emplaceDDict do idx &= mask; idx++ which allows idx to become tableSize (64) OOB when probing collides on last slot. IDs 3 and 47 both XXH64 hash to slot 63. Repro (mode 0 from P2447503582): register dictID 3 (slot 63), compress, patch frame header dictID to 47, decompress with refMultipleDDicts. With ASAN, buggy code triggers heap-buffer-overflow at slot 64. Without ASAN it returns dictionary mismatch and hides the bug, so CI must run with -fsanitize=address to catch it. This is the first commit on the fix branch - vulnerability still present so test passes without ASAN but would abort under ASAN, proving the bug. Fix will be second commit. Test: test217 DDict hashset OOB T283341343 (ASAN) Ref: T283341343
Probe loop did idx &= mask; idx++ which allows idx to become tableSize (64) OOB when collision hits last slot. With 3 and 47 both hashing to 63, getDDict reads past allocation. On glibc it returns NULL via slack and hides as dict mismatch; on jemalloc/ASAN it crashes / heap-buffer-overflow. Fix to idx = (idx + 1) & mask in both emplaceDDict and getDDict. This is the second commit on the fix branch, makes test217 pass under ASAN and fixes the reported wild pointer read. Fixes T283341343
Second probe bug in ZSTD_DDictHashSet_emplaceDDict did idx &= mask; idx++ allowing 8-byte OOB write at slot 64 when inserting colliding IDs 3 and 47 both hashing to 63. Rely on ASAN to catch heap-buffer-overflow on write (same as read path). Without ASAN glibc slack hides it, so test passes but would be caught in ASAN CI. Complements test217 which covered getDDict read path. Fixes T283341343 write path
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.
DDict hashset OOB with
ZSTD_d_refMultipleDDicts(T283341343)