]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
deflate_medium: Make sure we have enough lookahead before trying to scan for matches.
authorMika Lindqvist <postmaster@raasu.org>
Fri, 17 Mar 2017 19:36:38 +0000 (21:36 +0200)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Fri, 24 Mar 2017 20:56:23 +0000 (21:56 +0100)
* longest_match: Abort if match is in future

deflate_medium.c
match.c

index 972f5a840bbc1c005c510885c783a89f72a68381..2a12d4bfd08285ab02e36fdf2c71ca45462014b7 100644 (file)
@@ -264,7 +264,7 @@ block_state deflate_medium(deflate_state *s, int flush) {
         insert_match(s, current_match);
 
         /* now, look ahead one */
-        if (s->lookahead > MIN_LOOKAHEAD) {
+        if (s->lookahead > MIN_LOOKAHEAD && (current_match.strstart + current_match.match_length) < (s->window_size - MIN_LOOKAHEAD)) {
             s->strstart = current_match.strstart + current_match.match_length;
             hash_head = insert_string(s, s->strstart, 1);
 
diff --git a/match.c b/match.c
index 87e3d9655d5f47f8f4c3432d9fb520a76e2ec45a..b731246c0031af5684f2839b2454f311422616d0 100644 (file)
--- a/match.c
+++ b/match.c
@@ -84,7 +84,9 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) {
 
     Assert((unsigned long)s->strstart <= s->window_size - MIN_LOOKAHEAD, "need lookahead");
     do {
-        Assert(cur_match < s->strstart, "no future");
+        if (cur_match >= s->strstart) {
+          break;
+        }
         match = s->window + cur_match;
 
         /*
@@ -203,7 +205,9 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) {
     Assert((unsigned long)s->strstart <= s->window_size - MIN_LOOKAHEAD, "need lookahead");
     do {
         unsigned char *match;
-        Assert(cur_match < s->strstart, "no future");
+        if (cur_match >= s->strstart) {
+          break;
+        }
         match = s->window + cur_match;
 
         /*
@@ -375,7 +379,9 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) {
     Assert((unsigned long)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
 
     do {
-        Assert(cur_match < s->strstart, "no future");
+        if (cur_match >= s->strstart) {
+          break;
+        }
 
         /* Skip to next match if the match length cannot increase
          * or if the match length is less than 2.  Note that the checks below