]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Move check for match length in deflate_quick to check_match.
authorNathan Moinvaziri <nathan@nathanm.com>
Tue, 2 Jun 2020 16:17:56 +0000 (09:17 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Mon, 8 Jun 2020 19:16:31 +0000 (21:16 +0200)
deflate.c
deflate_quick.c

index 46f05165cc8ea6c4472acebee61c57532faa8377..2a32c9175e3dcef64b0779c9bf727f4d84cc01e0 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -1216,6 +1216,11 @@ static void lm_init(deflate_state *s) {
  * Check that the match at match_start is indeed a match.
  */
 void check_match(deflate_state *s, Pos start, Pos match, int length) {
+    /* check that the match length is valid*/
+    if (length < MIN_MATCH || length > MAX_MATCH) {
+        fprintf(stderr, " start %u, match %u, length %d\n", start, match, length);
+        z_error("invalid match length");
+    }
     /* check that the match is indeed a match */
     if (memcmp(s->window + match, s->window + start, length) != EQUAL) {
         fprintf(stderr, " start %u, match %u, length %d\n", start, match, length);
index cd79af4ffd0fb593b0f04604fa1a55798efaf24c..70a7e345d16d9d7d66fe27b461cdb6daebd879e8 100644 (file)
@@ -68,9 +68,6 @@ ZLIB_INTERNAL block_state deflate_quick(deflate_state *s, int flush) {
                     if (match_len > s->lookahead)
                         match_len = s->lookahead;
 
-                    if (match_len > MAX_MATCH)
-                        match_len = MAX_MATCH;
-
                     check_match(s, s->strstart, hash_head, match_len);
 
                     zng_tr_emit_dist(s, static_ltree, static_dtree, match_len - MIN_MATCH, dist);