]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Assert that Dict and Current Window are Adjacent in Index Space 1117/head
authorW. Felix Handte <w@felixhandte.com>
Wed, 23 May 2018 20:00:17 +0000 (16:00 -0400)
committerW. Felix Handte <w@felixhandte.com>
Wed, 23 May 2018 21:53:03 +0000 (17:53 -0400)
lib/compress/zstd_compress.c
lib/compress/zstd_fast.c

index 105cea44b351e3af678c7d563875c6c5f15ac258..00f3e789d6bac20098e3625d3e55814a382c60b2 100644 (file)
@@ -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;
index bf962a1756f968ee8df0c8783c56bcb3167001d1..3bac2bddd3af1703bb218c9386b58f5d1208d6d2 100644 (file)
@@ -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);