From: Nick Terrell Date: Wed, 10 Apr 2019 01:02:22 +0000 (-0700) Subject: [fuzzer] Use ZSTD_DCtx_loadDictionary_advanced() half the time X-Git-Tag: v1.4.0^2~8^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c45dec12c59beafacd14507bee0150a69cac7726;p=thirdparty%2Fzstd.git [fuzzer] Use ZSTD_DCtx_loadDictionary_advanced() half the time --- diff --git a/tests/fuzz/dictionary_decompress.c b/tests/fuzz/dictionary_decompress.c index bdecdef7a..7d3a7678a 100644 --- a/tests/fuzz/dictionary_decompress.c +++ b/tests/fuzz/dictionary_decompress.c @@ -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 diff --git a/tests/fuzz/dictionary_round_trip.c b/tests/fuzz/dictionary_round_trip.c index ceadbbc9d..e28c65c98 100644 --- a/tests/fuzz/dictionary_round_trip.c +++ b/tests/fuzz/dictionary_round_trip.c @@ -30,6 +30,7 @@ static size_t roundTripTest(void *result, size_t resultCapacity, void *compressed, size_t compressedCapacity, const void *src, size_t srcSize) { + ZSTD_dictContentType_e dictContentType = ZSTD_dct_auto; FUZZ_dict_t dict = FUZZ_train(src, srcSize, &seed); size_t cSize; if ((FUZZ_rand(&seed) & 15) == 0) { @@ -41,18 +42,24 @@ static size_t roundTripTest(void *result, size_t resultCapacity, dict.buff, dict.size, cLevel); } else { + dictContentType = FUZZ_rand32(&seed, 0, 2); FUZZ_setRandomParameters(cctx, srcSize, &seed); /* Disable checksum so we can use sizes smaller than compress bound. */ FUZZ_ZASSERT(ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 0)); - FUZZ_ZASSERT(ZSTD_CCtx_loadDictionary(cctx, dict.buff, dict.size)); + FUZZ_ZASSERT(ZSTD_CCtx_loadDictionary_advanced( + cctx, dict.buff, dict.size, + (ZSTD_dictLoadMethod_e)FUZZ_rand32(&seed, 0, 1), + dictContentType)); cSize = ZSTD_compress2(cctx, compressed, compressedCapacity, src, srcSize); } FUZZ_ZASSERT(cSize); + FUZZ_ZASSERT(ZSTD_DCtx_loadDictionary_advanced( + dctx, dict.buff, dict.size, + (ZSTD_dictLoadMethod_e)FUZZ_rand32(&seed, 0, 1), + dictContentType)); { - size_t const ret = ZSTD_decompress_usingDict(dctx, - result, resultCapacity, - compressed, cSize, - dict.buff, dict.size); + size_t const ret = ZSTD_decompressDCtx( + dctx, result, resultCapacity, compressed, cSize); free(dict.buff); return ret; }