-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bad integer wraparound in repcode index for fast, dfast, lazy #2610
Conversation
Any measurable performance impact ? |
No, according to
|
@senhuang42 Does this bug exist in other extDict match finders? |
Looking at the |
e2cd358
to
ca98d2f
Compare
This problem exists in I did many runs on Benchmarks to check for speed perturbations:
|
0a6e67a
to
8baf068
Compare
The speed difference is very minor and very acceptable, |
Why are you comparing I interpret comparing If you end up going the |
I'm using
I was directly converting from the I guess my actual question then is: why is |
Yes, totally |
Ah good point, sometimes we search at Could you add some comments explaining why we are comparing the offsets instead of the indices? |
8baf068
to
b54fe71
Compare
Ah, makes sense. I'll just change the comparison to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks correct to me, thanks for fixing this! Just one minor comment for consistency, and make sure the tests pass, and it looks good to me!
lib/compress/zstd_double_fast.c
Outdated
&& (MEM_read32(repMatch) == MEM_read32(ip+1)) ) { | ||
const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend; | ||
const BYTE* repMatchEnd = offset_1 > curr+1 - prefixStartIndex ? dictEnd : iend; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be necessary to change, here and elsewhere. We should only need to change the comparison on like 412. If the comparison succeeds, then we know it won't underflow.
Also repBase
and repMatch
are calculated using repIndex
so it is a bit confusing to see repMatchEnd
calculated differently.
b54fe71
to
e6c8a5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM assuming the tests all pass!
I'm going to go ahead and merge this so OSS-Fuzz can pick up these changes in the morning and continue fuzzing. |
The recently improved fuzz coverage of overflow correction has discovered a long-standing bug in
ZSTD_compressBlock_lazy_extDict_generic()
. There's a bad condition that could cause underflows if a repcode existed in a different segment thanip
.The original comment says
/* intentional overflow */
, but that actually only correctly applies to the first condition tested - it's not intentional for the second one.The transformation, step-by-step to show correctness:
repIndex > windowLow
→
repCurrent - offset_2 > windowLow
→
-offset_2 > windowLow - repCurrent
→
offset_2 < repCurrent - windowLow
Test Plan: