]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix CDict Attachment to Handle CDicts with Non-Zero Starts 1269/head
authorW. Felix Handte <w@felixhandte.com>
Wed, 8 Aug 2018 00:05:05 +0000 (17:05 -0700)
committerW. Felix Handte <w@felixhandte.com>
Wed, 8 Aug 2018 01:14:14 +0000 (18:14 -0700)
CDicts were previously guaranteed to be generated with `lowLimit=dictLimit=0`.
This is no longer true, and so the old length and index calculations are no
longer valid. This diff fixes them to handle non-zero start indices in CDicts.

lib/compress/zstd_compress.c

index 3ebfd019f43c873f83e3a8185279371917dbe333..ed3aab871b9e4ca5e58c10b11d7d7f2e5afd83d8 100644 (file)
@@ -1284,8 +1284,9 @@ static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx,
     }
 
     if (attachDict) {
-        const U32 cdictLen = (U32)( cdict->matchState.window.nextSrc
+        const U32 cdictEnd = (U32)( cdict->matchState.window.nextSrc
                                   - cdict->matchState.window.base);
+        const U32 cdictLen = cdictEnd - cdict->matchState.window.dictLimit;
         if (cdictLen == 0) {
             /* don't even attach dictionaries with no contents */
             DEBUGLOG(4, "skipping attaching empty dictionary");
@@ -1295,9 +1296,9 @@ static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx,
 
             /* 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 < cdictLen) {
+            if (cctx->blockState.matchState.window.dictLimit < cdictEnd) {
                 cctx->blockState.matchState.window.nextSrc =
-                    cctx->blockState.matchState.window.base + cdictLen;
+                    cctx->blockState.matchState.window.base + cdictEnd;
                 ZSTD_window_clear(&cctx->blockState.matchState.window);
             }
             cctx->blockState.matchState.loadedDictEnd = cctx->blockState.matchState.window.dictLimit;