-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add DDS to oss fuzzer #2586
Add DDS to oss fuzzer #2586
Conversation
Looks like something is not quite happy with how DDS adjusts its parameters and the increase and/or decrease of |
Also, local testing reveals that this assert is also failing Line 531 in 3eb3845
|
cc @felixhandte |
So I think the two changes should be the correct fix. If I'm not mistaken, the original seems to indicate that there was never any actual adjustment of the DDSS |
lib/compress/zstd_compress.c
Outdated
@@ -6168,7 +6168,7 @@ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEV | |||
|
|||
static ZSTD_compressionParameters ZSTD_dedicatedDictSearch_getCParams(int const compressionLevel, size_t const dictSize) | |||
{ | |||
ZSTD_compressionParameters cParams = ZSTD_getCParams_internal(compressionLevel, 0, dictSize, ZSTD_cpm_createCDict); | |||
ZSTD_compressionParameters cParams = ZSTD_getCParams_internal(compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN, dictSize, ZSTD_cpm_createCDict); |
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.
Makes sense.
lib/compress/zstd_compress.c
Outdated
@@ -4795,7 +4795,7 @@ ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced2( | |||
if (cctxParams.enableDedicatedDictSearch) { | |||
cParams = ZSTD_dedicatedDictSearch_getCParams( | |||
cctxParams.compressionLevel, dictSize); | |||
ZSTD_overrideCParams(&cParams, &cctxParams.cParams); | |||
ZSTD_overrideCParams(&cctxParams.cParams, &cParams); |
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.
Hm. The original may be mistaken, but I don't think this is a correct fix.
This call is of the form ZSTD_overrideCParams(dst, src)
. This had been part of a multi-step resolution of params into the local cParams
. The intent here is to first get the default cparams for the level, and then override those params with any explicit cparams that were set in the cctxparams by the user. These resolved params are then fed back into the cctxparams (on :4812) and passed down the stack.
With this new version, we will just ignore any explicit cparams set by the user. Which might well fix the assertion failure you're seeing, if the clevel derived params are all safe, but the fuzzer is setting bad cparams that aren't getting caught and rejected.
But then the correct fix would be to correctly validate the cparam set for ddss.
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 detailed explanation is probably worth becoming a code comment
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.
That makes sense: so the idea here is that if hLog
is explicitly set, DDS will not override that by adding 2 to it.
But the actual issue here is that if we set hLog = 7
explicitly, DDS will not override. But later on, ZSTD_dedicatedDictSearch_revertCParams()
is called anyways, subtracting 2 from the hLog
, making us end up with an invalid hLog
of 5 in ZSTD_resetCCtx_byAttachingCDict()
here:
zstd/lib/compress/zstd_compress.c
Lines 1996 to 2016 in 3eb3845
ZSTD_resetCCtx_byAttachingCDict(ZSTD_CCtx* cctx, | |
const ZSTD_CDict* cdict, | |
ZSTD_CCtx_params params, | |
U64 pledgedSrcSize, | |
ZSTD_buffered_policy_e zbuff) | |
{ | |
DEBUGLOG(4, "ZSTD_resetCCtx_byAttachingCDict() pledgedSrcSize=%zu", pledgedSrcSize); | |
{ | |
ZSTD_compressionParameters adjusted_cdict_cParams = cdict->matchState.cParams; | |
unsigned const windowLog = params.cParams.windowLog; | |
assert(windowLog != 0); | |
/* Resize working context table params for input only, since the dict | |
* has its own tables. */ | |
/* pledgedSrcSize == 0 means 0! */ | |
if (cdict->matchState.dedicatedDictSearch) { | |
ZSTD_dedicatedDictSearch_revertCParams(&adjusted_cdict_cParams); | |
} | |
params.cParams = ZSTD_adjustCParams_internal(adjusted_cdict_cParams, pledgedSrcSize, | |
cdict->dictContentSize, ZSTD_cpm_attachDict); |
At this point in the code, is it even possible to tell whether or not the hLog
is an hLog
that was explicitly set or an hLog
that was adjusted because DDS is available? Ideally, we'd want to be able to detect the latter case, and only subtract from hLog
then.
Maybe we can just call ZSTD_clampCParams()
on the ZSTD_adjustCParams_internal()
call right after, but that would still mean that the hLog
could still get reduced when it shouldn't be.
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.
Why would the interpretation of hlog
by DDS be different, depending on this parameter being automatically determined or explicitly set ? The way hlog
is set should not matter.
Moreover, the interpretation of hlog
should remain local.
If DDS considers that a hlog==7
will actually be interpreted as 5 for its own use, that's fine,
but this "interpreted value" should not be confused with the parameter hlog
.
As a consequence, this interpretation should remain private within DDS, and in no way impact any other part of the system, not even indirectly.
I've pushed @felixhandte's fix for all the assert issues onto this PR in the latest commit, it should fix the issue. |
Thanks @senhuang42, DDS coverage looks good now! |
DDS wasn't getting fuzzed, this adds it (back?) to OSS-Fuzz