]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix segfault in zstreamtest MT 524/head
authorNick Terrell <terrelln@fb.com>
Fri, 27 Jan 2017 23:42:36 +0000 (15:42 -0800)
committerNick Terrell <terrelln@fb.com>
Fri, 27 Jan 2017 23:42:36 +0000 (15:42 -0800)
It was reading beyond the end of the input buffer because no errors were
detected. Once that was fixed, it wasn't making forward progress because
no errors were detected and it was waiting for input.

tests/zstreamtest.c

index bef8734c7f866d2c2a9095e8e8223ee25300eebb..e451535c4d95330f8264f39998e9c14d79c9ef00 100644 (file)
@@ -933,10 +933,13 @@ static int fuzzerTests_MT(U32 seed, U32 nbTests, unsigned startTest, double comp
                 size_t const randomCSrcSize = FUZ_randomLength(&lseed, maxSampleLog);
                 size_t const randomDstSize = FUZ_randomLength(&lseed, maxSampleLog);
                 size_t const adjustedDstSize = MIN(dstBufferSize - outBuff.pos, randomDstSize);
+                size_t const adjustedCSrcSize = MIN(cSize - inBuff.pos, randomCSrcSize);
                 outBuff.size = outBuff.pos + adjustedDstSize;
-                inBuff.size  = inBuff.pos + randomCSrcSize;
+                inBuff.size  = inBuff.pos + adjustedCSrcSize;
                 {   size_t const decompressError = ZSTD_decompressStream(zd, &outBuff, &inBuff);
                     if (ZSTD_isError(decompressError)) break;   /* error correctly detected */
+                    /* No forward progress possible */
+                    if (outBuff.pos < outBuff.size && inBuff.pos == cSize) break;
     }   }   }   }
     DISPLAY("\r%u fuzzer tests completed   \n", testNb);