From: Mika Lindqvist Date: Fri, 17 Mar 2017 19:36:38 +0000 (+0200) Subject: deflate_medium: Make sure we have enough lookahead before trying to scan for matches. X-Git-Tag: 1.9.9-b1~661 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75e76eebeb08dccea44a1d9933699f7f9a0a97ea;p=thirdparty%2Fzlib-ng.git deflate_medium: Make sure we have enough lookahead before trying to scan for matches. * longest_match: Abort if match is in future --- diff --git a/deflate_medium.c b/deflate_medium.c index 972f5a840..2a12d4bfd 100644 --- a/deflate_medium.c +++ b/deflate_medium.c @@ -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 87e3d9655..b731246c0 100644 --- 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