]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed RLE detection test
authorYann Collet <cyan@fb.com>
Thu, 17 Oct 2024 20:21:55 +0000 (13:21 -0700)
committerYann Collet <cyan@fb.com>
Thu, 17 Oct 2024 20:21:55 +0000 (13:21 -0700)
lib/compress/zstd_compress.c
tests/fuzzer.c

index eb7b06df98023a371d956802c02d4938b48ad2ca..25a11f070a742e27b24e6734f502105ece688ac0 100644 (file)
@@ -4491,14 +4491,14 @@ static void ZSTD_overflowCorrectIfNeeded(ZSTD_matchState_t* ms,
 
 static size_t ZSTD_optimalBlockSize(const void* src, size_t srcSize, size_t blockSizeMax, ZSTD_strategy strat, S64 savings)
 {
-    if (srcSize <= 128 KB || blockSizeMax < 128 KB)
-        return MIN(srcSize, blockSizeMax);
-    (void)strat;
     if (strat >= ZSTD_btlazy2)
         return ZSTD_splitBlock_4k(src, srcSize, blockSizeMax);
+    if (srcSize <= 128 KB || blockSizeMax < 128 KB)
+        return MIN(srcSize, blockSizeMax);
     /* blind split strategy
-     * heuristic, just tested as being "generally better"
-     * do not split incompressible data though: just respect the 3 bytes per block overhead limit.
+     * no cpu cost, but can over-split homegeneous data.
+     * heuristic, tested as being "generally better".
+     * do not split incompressible data though: respect the 3 bytes per block overhead limit.
      */
     return savings ? 92 KB : 128 KB;
 }
index ead3cc8ddca7946fb4b205d5fee6e9375f669f4a..f5a89435412c83b4919b624413327548f8be6503 100644 (file)
@@ -3653,16 +3653,19 @@ static int basicUnitTests(U32 const seed, double compressibility)
         ZSTD_freeDCtx(dctx);
     }
 
-    /* long rle test */
+    /* rle detection test: must compress better blocks with a single identical byte repeated */
     {   size_t sampleSize = 0;
-        size_t expectedCompressedSize = 39; /* block 1, 2: compressed, block 3: RLE, zstd 1.4.4 */
-        DISPLAYLEVEL(3, "test%3i : Long RLE test : ", testNb++);
-        memset((char*)CNBuffer+sampleSize, 'B', 256 KB - 1);
-        sampleSize += 256 KB - 1;
-        memset((char*)CNBuffer+sampleSize, 'A', 96 KB);
-        sampleSize += 96 KB;
+        size_t maxCompressedSize = 46; /* block 1, 2: compressed, block 3: RLE, zstd 1.4.4 */
+        DISPLAYLEVEL(3, "test%3i : RLE detection test : ", testNb++);
+        memset((char*)CNBuffer+sampleSize, 'B', 256 KB - 2);
+        sampleSize += 256 KB - 2;
+        memset((char*)CNBuffer+sampleSize, 'A', 100 KB);
+        sampleSize += 100 KB;
         cSize = ZSTD_compress(compressedBuffer, ZSTD_compressBound(sampleSize), CNBuffer, sampleSize, 1);
-        if (ZSTD_isError(cSize) || cSize > expectedCompressedSize) goto _output_error;
+        if (ZSTD_isError(cSize) || cSize > maxCompressedSize) {
+            DISPLAYLEVEL(4, "error: cSize %u > %u expected ! \n", (unsigned)cSize, (unsigned)maxCompressedSize);
+            goto _output_error;
+        }
         { CHECK_NEWV(regenSize, ZSTD_decompress(decodedBuffer, sampleSize, compressedBuffer, cSize));
           if (regenSize!=sampleSize) goto _output_error; }
         DISPLAYLEVEL(3, "OK \n");