Skip to content
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

Merged
merged 2 commits into from
Apr 24, 2021
Merged

Add DDS to oss fuzzer #2586

merged 2 commits into from
Apr 24, 2021

Conversation

senhuang42
Copy link
Contributor

@senhuang42 senhuang42 commented Apr 22, 2021

DDS wasn't getting fuzzed, this adds it (back?) to OSS-Fuzz

@senhuang42
Copy link
Contributor Author

senhuang42 commented Apr 22, 2021

Looks like something is not quite happy with how DDS adjusts its parameters and the increase and/or decrease of hashLog.

@senhuang42
Copy link
Contributor Author

Also, local testing reveals that this assert is also failing make -j regressiontest:

assert(chainPos <= chainSize); /* I believe this is guaranteed... */

@Cyan4973
Copy link
Contributor

Also, local testing reveals that this assert is also failing make -j regressiontest:

assert(chainPos <= chainSize); /* I believe this is guaranteed... */

cc @felixhandte

@senhuang42
Copy link
Contributor Author

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 hashLog? Would this change/improve the performance of DDSS?

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

@@ -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);
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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_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.

Copy link
Contributor

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.

@senhuang42
Copy link
Contributor Author

I've pushed @felixhandte's fix for all the assert issues onto this PR in the latest commit, it should fix the issue.

@senhuang42 senhuang42 merged commit 14c11c7 into facebook:dev Apr 24, 2021
@terrelln
Copy link
Contributor

Thanks @senhuang42, DDS coverage looks good now!

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.

5 participants