From: W. Felix Handte Date: Wed, 23 May 2018 20:00:17 +0000 (-0400) Subject: Assert that Dict and Current Window are Adjacent in Index Space X-Git-Tag: v1.3.5~3^2~44^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9c7e67125d95d751e934870fdf611fbe0995934;p=thirdparty%2Fzstd.git Assert that Dict and Current Window are Adjacent in Index Space --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 105cea44b..00f3e789d 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2210,6 +2210,11 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc, ZSTD_resetSeqStore(&(zc->seqStore)); ms->opt.symbolCosts = &zc->blockState.prevCBlock->entropy; /* required for optimal parser to read stats from dictionary */ + /* a gap between an attached dict and the current window is not safe, + * they must remain adjacent, and when that stops being the case, the dict + * must be unset */ + assert(ms->dictMatchState == NULL || ms->loadedDictEnd == ms->window.dictLimit); + /* limited update after a very long match */ { const BYTE* const base = ms->window.base; const BYTE* const istart = (const BYTE*)src; diff --git a/lib/compress/zstd_fast.c b/lib/compress/zstd_fast.c index bf962a175..3bac2bddd 100644 --- a/lib/compress/zstd_fast.c +++ b/lib/compress/zstd_fast.c @@ -72,7 +72,7 @@ size_t ZSTD_compressBlock_fast_generic( const BYTE* const dictEnd = dictMode == ZSTD_dictMatchState ? dms->window.nextSrc : NULL; const U32 dictIndexDelta = dictMode == ZSTD_dictMatchState ? - ms->loadedDictEnd - (U32)(dictEnd - dictBase) : + prefixLowestIndex - (U32)(dictEnd - dictBase) : 0; const U32 dictAndPrefixLength = (U32)(ip - prefixLowest + dictEnd - dictLowest);