Restored variable output size fuzzer test
authorYann Collet <yann.collet.73@gmail.com>
Sat, 13 Sep 2014 20:21:41 +0000 (21:21 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Sat, 13 Sep 2014 20:21:41 +0000 (21:21 +0100)
Quickfix frame decompression
Small speed optimization frame decompression

lz4frame.c
programs/frametest.c

index 390af0e..7bc2319 100644 (file)
@@ -775,15 +775,6 @@ static void LZ4F_saveDict(LZ4F_dctx_internal_t* dctxPtr, const BYTE* decoded, si
 
 static void LZ4F_pointDict(LZ4F_dctx_internal_t* dctxPtr, const BYTE* decoded, size_t decodedSize)
 {
-    /* large decoded block */
-    if (decodedSize >= (64 KB - 1))
-    {
-        dctxPtr->dict = (BYTE*)decoded;
-        dctxPtr->dictSize = decodedSize;
-        dctxPtr->tmpOut = dctxPtr->tmpOutBuffer + 64 KB;
-        return;
-    }
-
     /* decoded block in the continuity of dictionary */
     if (dctxPtr->dict + dctxPtr->dictSize == decoded)
     {
@@ -800,6 +791,15 @@ static void LZ4F_pointDict(LZ4F_dctx_internal_t* dctxPtr, const BYTE* decoded, s
         return;
     }
 
+    /* large decoded block */
+    if (decodedSize >= (64 KB - 1))
+    {
+        dctxPtr->dict = (BYTE*)decoded;
+        dctxPtr->dictSize = decodedSize;
+        dctxPtr->tmpOut = dctxPtr->tmpOutBuffer + 64 KB;
+        return;
+    }
+
     /* small block, and not contiguous : let's save that */
     LZ4F_saveDict(dctxPtr, decoded, decodedSize);
 }
@@ -953,6 +953,11 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext,
                     break;
                 }
                 dctxPtr->dStage = dstage_getCBlock;
+                if (dstPtr==dstEnd)
+                {
+                    nextSrcSizeHint = nextCBlockSize + 4;
+                    doAnotherStage = 0;
+                }
                 break;
             }
 
index 8be7752..ba24fe1 100644 (file)
@@ -466,12 +466,11 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
             while (ip < iend)
             {
                 unsigned nbBitsI = (FUZ_rand(&randState) % (maxBits-1)) + 1;
-                unsigned nbBitsO = (FUZ_rand(&randState) % (maxBits-1)) + 1;
+                unsigned nbBitsO = (FUZ_rand(&randState) % (maxBits)) + 1;
                 size_t iSize = (FUZ_rand(&randState) & ((1<<nbBitsI)-1)) + 1;
-                size_t oSize = (FUZ_rand(&randState) & ((1<<nbBitsO)-1)) + 1;
+                size_t oSize = (FUZ_rand(&randState) & ((1<<nbBitsO)-1)) + 2;
                 if (iSize > (size_t)(iend-ip)) iSize = iend-ip;
                 if (oSize > (size_t)(oend-op)) oSize = oend-op;
-                oSize = oend-op;
                 result = LZ4F_decompress(dCtx, op, &oSize, ip, &iSize, NULL);
                 if (result == (size_t)-ERROR_checksum_invalid) locateBuffDiff((BYTE*)srcBuffer+srcStart, decodedBuffer, srcSize);
                 CHECK(LZ4F_isError(result), "Decompression failed (error %i)", (int)result);