]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed a bug in zstreamtest
authorYann Collet <cyan@fb.com>
Wed, 27 Sep 2017 07:39:41 +0000 (00:39 -0700)
committerYann Collet <cyan@fb.com>
Wed, 27 Sep 2017 07:39:41 +0000 (00:39 -0700)
decoder output buffer would receive a wrong size.

In previous version, ZSTD_decompressStream() would blindly trust the caller that pos <= size.
In this version, this condition is actively checked,
and the function returns an error code if this condition is not respected.

This check could also be done with an assert(),
but since this is a user-facing interface, it seems better to keep this check at runtime.

lib/decompress/zstd_decompress.c
tests/zstreamtest.c

index dc6ab3f3ea94335a8c11a12f287ca50ff8c05b9c..0380f6a109b4ba46ee02456b51d3f6d81f5ddba4 100644 (file)
@@ -2404,8 +2404,16 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
     U32 someMoreWork = 1;
 
     DEBUGLOG(5, "ZSTD_decompressStream");
-    if (input->pos > input->size) return ERROR(GENERIC);   /* forbidden */
-    if (output->pos > output->size) return ERROR(GENERIC); /* forbidden */
+    if (input->pos > input->size) {  /* forbidden */
+        DEBUGLOG(5, "in: pos: %u   vs size: %u",
+                    (U32)input->pos, (U32)input->size);
+        return ERROR(GENERIC);
+    }
+    if (output->pos > output->size) {  /* forbidden */
+        DEBUGLOG(5, "out: pos: %u   vs size: %u",
+                    (U32)output->pos, (U32)output->size);
+        return ERROR(GENERIC);
+    }
     DEBUGLOG(5, "input size : %u", (U32)(input->size - input->pos));
 
 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
index 613a879bfff6bdeee974e02faa8658ab68ecf8a4..1f682038f9ffefa70c68b914ced41750ecbe0ee9 100644 (file)
@@ -914,7 +914,7 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compres
                 size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog);
                 size_t const dstBuffSize = MIN(dstBufferSize - totalGenSize, randomDstSize);
                 inBuff.size = inBuff.pos + readCSrcSize;
-                outBuff.size = inBuff.pos + dstBuffSize;
+                outBuff.size = outBuff.pos + dstBuffSize;
                 decompressionResult = ZSTD_decompressStream(zd, &outBuff, &inBuff);
                 if (ZSTD_getErrorCode(decompressionResult) == ZSTD_error_checksum_wrong) {
                     DISPLAY("checksum error : \n");