]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fix scan_endstr offset in longest_match slow path. develop
authorNathan Moin Vaziri <nathan@nathanm.com>
Sat, 11 Apr 2026 03:38:29 +0000 (20:38 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 12 May 2026 17:59:12 +0000 (19:59 +0200)
LONGEST_MATCH_SLOW was using len - (STD_MIN_MATCH+1) instead of
len - (STD_MIN_MATCH-1) for the end-of-string hash probe, hashing a
window inside the already-matched region instead of ending one byte
past the current match. The slow path was missing match extensions
it should have been finding. The comment and the upstream fast_zlib
source both specify the correct offset.

Closes #2248.

Reported-by: Sergey "Shnatsel" Davidoff <291257+Shnatsel@users.noreply.github.com>
Reported-by: Folkert de Vries <7949978+folkertdev@users.noreply.github.com>
match_tpl.h

index 88f4588a133eb998faf19d25cd8ed62209d868f0..384b83b79e13bf63980029c7c5d74307bf3f5d56 100644 (file)
@@ -205,7 +205,7 @@ Z_INTERNAL uint32_t LONGEST_MATCH(deflate_state *const s, uint32_t cur_match) {
                  * us include one more byte into hash - the byte which will be checked
                  * in main loop now, and which allows to grow match by 1.
                  */
-                scan_endstr = scan + len - (STD_MIN_MATCH+1);
+                scan_endstr = scan + len - (STD_MIN_MATCH-1);
 
                 // use update_hash_roll for deflate_slow
                 hash = update_hash_roll(0, scan_endstr[0]);
@@ -214,7 +214,7 @@ Z_INTERNAL uint32_t LONGEST_MATCH(deflate_state *const s, uint32_t cur_match) {
 
                 pos = head[hash];
                 if (pos < cur_match) {
-                    match_offset = len - (STD_MIN_MATCH+1);
+                    match_offset = len - (STD_MIN_MATCH-1);
                     if (pos <= limit_base + match_offset)
                         return best_len;
                     cur_match = pos;