From 65f9cfeeec29724b5d48da088f7f325af1cfc01a Mon Sep 17 00:00:00 2001 From: senhuang42 Date: Wed, 30 Sep 2020 11:25:51 -0400 Subject: [PATCH] Add extra bounds check to prevent heap access after free ASAN error --- lib/compress/zstd_opt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index 1c1700328..d6c728462 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -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,