]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[lib] Fix dictionary + repcodes + optimal parser
authorNick Terrell <terrelln@fb.com>
Tue, 12 May 2020 05:27:34 +0000 (22:27 -0700)
committerNick Terrell <terrelln@fb.com>
Tue, 12 May 2020 17:36:53 +0000 (10:36 -0700)
lib/compress/zstd_opt.c

index 890ae9243e153ae79e69d2442ad6c81fda2c7f5b..36fff050cf5a8b24e63264c51a94864a4817dbbb 100644 (file)
@@ -569,7 +569,10 @@ U32 ZSTD_insertBtAndGetAllMatches (
             U32 repLen = 0;
             assert(current >= dictLimit);
             if (repOffset-1 /* intentional overflow, discards 0 and -1 */ < current-dictLimit) {  /* equivalent to `current > repIndex >= dictLimit` */
-                if (ZSTD_readMINMATCH(ip, minMatch) == ZSTD_readMINMATCH(ip - repOffset, minMatch)) {
+                /* We must validate the repcode offset because when we're using a dictionary the
+                 * valid offset range shrinks when the dictionary goes out of bounds.
+                 */
+                if ((repIndex >= windowLow) & (ZSTD_readMINMATCH(ip, minMatch) == ZSTD_readMINMATCH(ip - repOffset, minMatch))) {
                     repLen = (U32)ZSTD_count(ip+minMatch, ip+minMatch-repOffset, iLimit) + minMatch;
                 }
             } else {  /* repIndex < dictLimit || repIndex >= current */