]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Add extra bounds check to prevent heap access after free ASAN error
authorsenhuang42 <senhuang96@fb.com>
Wed, 30 Sep 2020 15:25:51 +0000 (11:25 -0400)
committersenhuang42 <senhuang96@fb.com>
Wed, 7 Oct 2020 17:56:25 +0000 (13:56 -0400)
lib/compress/zstd_opt.c

index 1c1700328fe00fc892399a601bdfdcfe64129c6c..d6c728462cd79f2711156cfa3d168d871bfb9ab1 100644 (file)
@@ -986,11 +986,11 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms,
      * since the base shifts back 131072 bytes (1 block) after the first block. The consequence is that
      * we should insert 35373 bytes into the 8th block, rather than 35373 bytes into the 7th block.
      */
-    if (ms->ldmSeqStore.size > 0) {
+    if (ms->ldmSeqStore.size > 0 && ms->ldmSeqStore.pos != ms->ldmSeqStore.size) {
         if (ms->ldmSeqStore.base != base) {
             int baseDiff = (int)(ms->ldmSeqStore.base - base);
             ms->ldmSeqStore.seq[ms->ldmSeqStore.pos].litLength += baseDiff;
-            ms->ldmSeqStore.base = ms->window.base;
+            ms->ldmSeqStore.base = base;
         }
         ldm_getNextMatch(&ms->ldmSeqStore, &ldmStartPosInBlock,
                          &ldmEndPosInBlock, &ldmOffset,