aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-22 23:45:00 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-22 23:45:00 -0700
commitfaa03d5141fad5ca0c34ac2a4a72b383668083aa (patch)
tree722090e054b5793584d7a88337c0ccdae4ba80a7
parentae1de165d7133d6ebe9a69b10abdc952d877b6ae (diff)
downloadzlib-faa03d5141fad5ca0c34ac2a4a72b383668083aa.tar.gz
zlib-faa03d5141fad5ca0c34ac2a4a72b383668083aa.tar.bz2
zlib-faa03d5141fad5ca0c34ac2a4a72b383668083aa.zip
Avoid searching past window for Z_RLE strategy.
Without this, Z_RLE could under some circumstances read one byte past the end of the allocated sliding window. This would normally not be a problem unless the window is right at the end of an allocated page, or if a bounds checker is being used.
-rw-r--r--deflate.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/deflate.c b/deflate.c
index d9d141a..f0765d3 100644
--- a/deflate.c
+++ b/deflate.c
@@ -1761,11 +1761,11 @@ local block_state deflate_rle(s, flush)
1761 for (;;) { 1761 for (;;) {
1762 /* Make sure that we always have enough lookahead, except 1762 /* Make sure that we always have enough lookahead, except
1763 * at the end of the input file. We need MAX_MATCH bytes 1763 * at the end of the input file. We need MAX_MATCH bytes
1764 * for the longest encodable run. 1764 * for the longest run, plus one for the unrolled loop.
1765 */ 1765 */
1766 if (s->lookahead < MAX_MATCH) { 1766 if (s->lookahead <= MAX_MATCH) {
1767 fill_window(s); 1767 fill_window(s);
1768 if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) { 1768 if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
1769 return need_more; 1769 return need_more;
1770 } 1770 }
1771 if (s->lookahead == 0) break; /* flush the current block */ 1771 if (s->lookahead == 0) break; /* flush the current block */
@@ -1788,6 +1788,7 @@ local block_state deflate_rle(s, flush)
1788 if (s->match_length > s->lookahead) 1788 if (s->match_length > s->lookahead)
1789 s->match_length = s->lookahead; 1789 s->match_length = s->lookahead;
1790 } 1790 }
1791 Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
1791 } 1792 }
1792 1793
1793 /* Emit match if have run of MIN_MATCH or longer, else emit literal */ 1794 /* Emit match if have run of MIN_MATCH or longer, else emit literal */