]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
add one valid test case
authorYann Collet <cyan@fb.com>
Tue, 24 Dec 2024 03:43:17 +0000 (19:43 -0800)
committerYann Collet <cyan@fb.com>
Tue, 24 Dec 2024 03:43:17 +0000 (19:43 -0800)
ZSTD_compressSequencesAndLiterals() may return a specific error code
when data to compress is non-compressible.

tests/fuzz/sequence_compression_api.c

index 32710afb936ef18bb5a734852fcc0fe4ff639776..21b6ac84e921eb1bf8e9ca8030d9bc396139d1d9 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #define ZSTD_STATIC_LINKING_ONLY
+#include "zstd_errors.h"
 
 #include <stddef.h>
 #include <stdlib.h>
@@ -275,7 +276,12 @@ static size_t roundTripTest_compressSequencesAndLiterals(
         return 0;
     }
     /* round-trip */
-    FUZZ_ZASSERT(cSize);
+    if (ZSTD_isError(cSize)) {
+         ZSTD_ErrorCode err = ZSTD_getErrorCode(cSize);
+         /* this specific error might happen as a result of data being uncompressible */
+         if (err != ZSTD_error_cannotProduce_uncompressedBlock)
+            FUZZ_ZASSERT(cSize);
+    }
     {   size_t const dSize = ZSTD_decompressDCtx(dctx, result, resultCapacity, compressed, cSize);
         FUZZ_ZASSERT(dSize);
         FUZZ_ASSERT_MSG(dSize == srcSize, "Incorrect regenerated size");