diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2024-01-19 12:19:53 -0800 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2024-01-19 12:19:53 -0800 |
commit | 7af6320ad78b390de42f414fabdc64dc6d67a5ea (patch) | |
tree | bc21367401967599a000b94d81ebb64af59292d4 /deflate.c | |
parent | 7b632b486a591aa28d3d98d0ed8aa2235ee34643 (diff) | |
download | zlib-7af6320ad78b390de42f414fabdc64dc6d67a5ea.tar.gz zlib-7af6320ad78b390de42f414fabdc64dc6d67a5ea.tar.bz2 zlib-7af6320ad78b390de42f414fabdc64dc6d67a5ea.zip |
Fix a bug in ZLIB_DEBUG compiles in check_match().
This avoids trying to compare a match starting one byte before the
current window. Thanks to @zmodem (Hans) for discovering this.
Diffstat (limited to 'deflate.c')
-rw-r--r-- | deflate.c | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -1556,13 +1556,21 @@ local uInt longest_match(deflate_state *s, IPos cur_match) { | |||
1556 | */ | 1556 | */ |
1557 | local void check_match(deflate_state *s, IPos start, IPos match, int length) { | 1557 | local void check_match(deflate_state *s, IPos start, IPos match, int length) { |
1558 | /* check that the match is indeed a match */ | 1558 | /* check that the match is indeed a match */ |
1559 | if (zmemcmp(s->window + match, | 1559 | Bytef *back = s->window + (int)match, *here = s->window + start; |
1560 | s->window + start, length) != EQUAL) { | 1560 | IPos len = length; |
1561 | fprintf(stderr, " start %u, match %u, length %d\n", | 1561 | if (match == (IPos)-1) { |
1562 | start, match, length); | 1562 | /* match starts one byte before the current window -- just compare the |
1563 | subsequent length-1 bytes */ | ||
1564 | back++; | ||
1565 | here++; | ||
1566 | len--; | ||
1567 | } | ||
1568 | if (zmemcmp(back, here, len) != EQUAL) { | ||
1569 | fprintf(stderr, " start %u, match %d, length %d\n", | ||
1570 | start, (int)match, length); | ||
1563 | do { | 1571 | do { |
1564 | fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); | 1572 | fprintf(stderr, "(%02x %02x)", *back++, *here++); |
1565 | } while (--length != 0); | 1573 | } while (--len != 0); |
1566 | z_error("invalid match"); | 1574 | z_error("invalid match"); |
1567 | } | 1575 | } |
1568 | if (z_verbose > 1) { | 1576 | if (z_verbose > 1) { |