]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[fuzzer] Use ZSTD_DCtx_loadDictionary_advanced() half the time 1576/head
authorNick Terrell <terrelln@fb.com>
Wed, 10 Apr 2019 01:02:22 +0000 (18:02 -0700)
committerNick Terrell <terrelln@fb.com>
Wed, 10 Apr 2019 01:02:22 +0000 (18:02 -0700)
tests/fuzz/dictionary_decompress.c
tests/fuzz/dictionary_round_trip.c

index bdecdef7ad3819a104862191c983aea22f6ae9ce..7d3a7678adc64f095d8e26fc4c2611af88814cdf 100644 (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
index ceadbbc9dd3148dfd5e84854fbbf1a17a2a5f273..e28c65c98f06d94d8889bd8e1a4e1ba3c9c97c29 100644 (file)
@@ -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;
     }