]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Avoid Undefined Behavior in Match Ptr Calculation
authorW. Felix Handte <w@felixhandte.com>
Tue, 15 May 2018 19:45:37 +0000 (15:45 -0400)
committerW. Felix Handte <w@felixhandte.com>
Wed, 23 May 2018 21:53:03 +0000 (17:53 -0400)
lib/compress/zstd_fast.c

index 09b1a8ec3293febd182037f6afc7bb95830ee462..b21bc7683c14934234e9b09492bd47bf3f52eee9 100644 (file)
@@ -99,10 +99,10 @@ size_t ZSTD_compressBlock_fast_generic(
         U32 const matchIndex = hashTable[h];
         const BYTE* match = base + matchIndex;
         const U32 repIndex = current + 1 - offset_1;
-        const BYTE* repBase = (dictMode == ZSTD_dictMatchState
+        const BYTE* repMatch = (dictMode == ZSTD_dictMatchState
                             && repIndex < prefixLowestIndex) ?
-                               dictBase - dictIndexDelta : base;
-        const BYTE* repMatch = repBase + repIndex;
+                               dictBase + (repIndex - dictIndexDelta) :
+                               base + repIndex;
         hashTable[h] = current;   /* update hash table */
 
         if (dictMode == ZSTD_dictMatchState