]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Permit Matching Against Lowest Valid Position
authorW. Felix Handte <w@felixhandte.com>
Wed, 26 Aug 2020 22:33:44 +0000 (18:33 -0400)
committerW. Felix Handte <w@felixhandte.com>
Thu, 10 Sep 2020 22:51:52 +0000 (18:51 -0400)
This comparison was previously faulty: the lowest valid position is itself
valid, and we should therefore be allowed to match against it.

lib/compress/zstd_lazy.c

index 684e7e56ea0b8047dce28dbc8dd9accd1c98f2c0..15df6125ea957a2742111a3bac67a7e35b239679 100644 (file)
@@ -544,7 +544,7 @@ size_t ZSTD_HcFindBestMatch_generic (
     /* HC4 match finder */
     matchIndex = ZSTD_insertAndFindFirstIndex_internal(ms, cParams, ip, mls);
 
-    for ( ; (matchIndex>lowLimit) & (nbAttempts>0) ; nbAttempts--) {
+    for ( ; (matchIndex>=lowLimit) & (nbAttempts>0) ; nbAttempts--) {
         size_t currentMl=0;
         if ((dictMode != ZSTD_extDict) || matchIndex >= dictLimit) {
             const BYTE* const match = base + matchIndex;
@@ -649,7 +649,7 @@ size_t ZSTD_HcFindBestMatch_generic (
 
         matchIndex = dms->hashTable[ZSTD_hashPtr(ip, dms->cParams.hashLog, mls)];
 
-        for ( ; (matchIndex>dmsLowestIndex) & (nbAttempts>0) ; nbAttempts--) {
+        for ( ; (matchIndex>=dmsLowestIndex) & (nbAttempts>0) ; nbAttempts--) {
             size_t currentMl=0;
             const BYTE* const match = dmsBase + matchIndex;
             assert(match+4 <= dmsEnd);