]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Make loadedDictEnd an Index, not the Dict Len
authorW. Felix Handte <w@felixhandte.com>
Tue, 22 May 2018 00:12:11 +0000 (20:12 -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_compress_internal.h
lib/compress/zstd_fast.c

index e49046fcb7386f01d8e1bb44e94b7ce12c67baa7..105cea44b351e3af678c7d563875c6c5f15ac258 100644 (file)
@@ -1209,6 +1209,8 @@ static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx,
      * in-place. We decide here which strategy to use. */
     const int attachDict = ( pledgedSrcSize <= 8 KB
                           || pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN )
+                        && !params.forceWindow /* dictMatchState isn't correctly
+                                                * handled in _enforceMaxDist */
                         && cdict->cParams.strategy == ZSTD_fast
                         && ZSTD_equivalentCParams(cctx->appliedParams.cParams,
                                                   cdict->cParams);
@@ -1244,7 +1246,7 @@ static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx,
                     cctx->blockState.matchState.window.base + cdictLen;
                 ZSTD_window_clear(&cctx->blockState.matchState.window);
             }
-            cctx->blockState.matchState.loadedDictEnd = params.forceWindow ? 0 : cdictLen;
+            cctx->blockState.matchState.loadedDictEnd = cctx->blockState.matchState.window.dictLimit;
         }
     } else {
         DEBUGLOG(4, "copying dictionary into context");
index a61fc374297212ae60bcb8b17d66fb14006cb8b6..a7666d5c5cbd0fbf73516c85997a6b47a60629f1 100644 (file)
@@ -594,14 +594,20 @@ MEM_STATIC U32 ZSTD_window_correctOverflow(ZSTD_window_t* window, U32 cycleLog,
  * ZSTD_window_enforceMaxDist():
  * Updates lowLimit so that:
  *    (srcEnd - base) - lowLimit == maxDist + loadedDictEnd
+ *
  * This allows a simple check that index >= lowLimit to see if index is valid.
  * This must be called before a block compression call, with srcEnd as the block
  * source end.
+ *
  * If loadedDictEndPtr is not NULL, we set it to zero once we update lowLimit.
  * This is because dictionaries are allowed to be referenced as long as the last
  * byte of the dictionary is in the window, but once they are out of range,
  * they cannot be referenced. If loadedDictEndPtr is NULL, we use
  * loadedDictEnd == 0.
+ *
+ * In normal dict mode, the dict is between lowLimit and dictLimit. In
+ * dictMatchState mode, lowLimit and dictLimit are the same, and the dictionary
+ * is below them. forceWindow and dictMatchState are therefore incompatible.
  */
 MEM_STATIC void ZSTD_window_enforceMaxDist(ZSTD_window_t* window,
                                            void const* srcEnd, U32 maxDist,
index 3bac2bddd3af1703bb218c9386b58f5d1208d6d2..bf962a1756f968ee8df0c8783c56bcb3167001d1 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 ?
-                                     prefixLowestIndex - (U32)(dictEnd - dictBase) :
+                                     ms->loadedDictEnd - (U32)(dictEnd - dictBase) :
                                      0;
     const U32 dictAndPrefixLength  = (U32)(ip - prefixLowest + dictEnd - dictLowest);