[fuzzer] Use ZSTD_DCtx_loadDictionary_advanced() half the time

This commit is contained in:
Nick Terrell
2019-04-09 18:02:22 -07:00
parent 10a3d4dca9
commit c45dec12c5
2 changed files with 22 additions and 8 deletions
+10 -3
View File
@@ -25,6 +25,7 @@ static size_t bufSize = 0;
int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
{
FUZZ_dict_t dict;
size_t neededBufSize;
uint32_t seed = FUZZ_seed(&src, &size);
@@ -41,15 +42,21 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
dctx = ZSTD_createDCtx();
FUZZ_ASSERT(dctx);
}
{
FUZZ_dict_t dict = FUZZ_train(src, size, &seed);
dict = FUZZ_train(src, size, &seed);
if (FUZZ_rand32(&seed, 0, 1) == 0) {
ZSTD_decompress_usingDict(dctx,
rBuf, neededBufSize,
src, size,
dict.buff, dict.size);
free(dict.buff);
} else {
FUZZ_ZASSERT(ZSTD_DCtx_loadDictionary_advanced(
dctx, dict.buff, dict.size,
(ZSTD_dictLoadMethod_e)FUZZ_rand32(&seed, 0, 1),
(ZSTD_dictContentType_e)FUZZ_rand32(&seed, 0, 2)));
ZSTD_decompressDCtx(dctx, rBuf, neededBufSize, src, size);
}
free(dict.buff);
#ifndef STATEFUL_FUZZING
ZSTD_freeDCtx(dctx); dctx = NULL;
#endif