]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Force Working Context Indices Greater than Dict Indices
authorW. Felix Handte <w@felixhandte.com>
Thu, 10 May 2018 21:17:10 +0000 (17:17 -0400)
committerW. Felix Handte <w@felixhandte.com>
Wed, 23 May 2018 21:53:03 +0000 (17:53 -0400)
lib/compress/zstd_compress.c

index f0576f0811ce20174e3c6474107a0e0ff3b5ecc4..e05882684023fab3f0d7516724955e463bbcf920 100644 (file)
@@ -1229,6 +1229,17 @@ static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx,
     if (attachDict) {
         DEBUGLOG(4, "attaching dictionary into context");
         cctx->blockState.matchState.dictMatchState = &cdict->matchState;
+
+        /* prep working match state so dict matches never have negative indices
+         * when they are translated to the working context's index space. */
+        if (cctx->blockState.matchState.window.dictLimit <
+            (U32)(cdict->matchState.window.nextSrc - cdict->matchState.window.base)) {
+            cctx->blockState.matchState.window.nextSrc =
+                cctx->blockState.matchState.window.base +
+                ( cdict->matchState.window.nextSrc
+                - cdict->matchState.window.base);
+            ZSTD_window_clear(&cctx->blockState.matchState.window);
+        }
     } else {
         DEBUGLOG(4, "copying dictionary into context");
         /* copy tables */