]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[ldm] Fix corner case where minMatch < 8 857/head
authorNick Terrell <terrelln@fb.com>
Tue, 19 Sep 2017 20:49:37 +0000 (13:49 -0700)
committerNick Terrell <terrelln@fb.com>
Tue, 19 Sep 2017 20:49:37 +0000 (13:49 -0700)
There is a potential read buffer overflow when minMatch < 8.

fix-fuzz-failure

lib/compress/zstd_ldm.c

index e7efecdb97b4e003e1b71abb572b059985c1553a..e40007c19936457f16cc6d6a5b7ec2526498331e 100644 (file)
@@ -295,7 +295,7 @@ size_t ZSTD_compressBlock_ldm_generic(ZSTD_CCtx* cctx,
     const U32   lowestIndex = cctx->dictLimit;
     const BYTE* const lowest = base + lowestIndex;
     const BYTE* const iend = istart + srcSize;
-    const BYTE* const ilimit = iend - ldmParams.minMatchLength;
+    const BYTE* const ilimit = iend - MAX(ldmParams.minMatchLength, HASH_READ_SIZE);
 
     const ZSTD_blockCompressor blockCompressor =
         ZSTD_selectBlockCompressor(cctx->appliedParams.cParams.strategy, 0);
@@ -499,7 +499,7 @@ static size_t ZSTD_compressBlock_ldm_extDict_generic(
     const BYTE* const lowPrefixPtr = base + dictLimit;
     const BYTE* const dictEnd = dictBase + dictLimit;
     const BYTE* const iend = istart + srcSize;
-    const BYTE* const ilimit = iend - ldmParams.minMatchLength;
+    const BYTE* const ilimit = iend - MAX(ldmParams.minMatchLength, HASH_READ_SIZE);
 
     const ZSTD_blockCompressor blockCompressor =
         ZSTD_selectBlockCompressor(ctx->appliedParams.cParams.strategy, 1);