summaryrefslogtreecommitdiff
path: root/deflate_fast.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2018-04-17 22:09:22 -0700
committerHans Kristian Rosbach <hk-github@circlestorm.org>2018-11-14 09:21:26 +0100
commitccbb3fef5a78d8e612a8fb10e615869a7efe4306 (patch)
tree64812c2d5afc75a90b70cce06ece0746b4f566b7 /deflate_fast.c
parent6b5e2ddbb75394722e37d3ab1d32ace9c48692ee (diff)
Fix a bug that can crash deflate on some input when using Z_FIXED.
This bug was reported by Danilo Ramos of Eideticom, Inc. It has lain in wait 13 years before being found! The bug was introduced in zlib 1.2.2.2, with the addition of the Z_FIXED option. That option forces the use of fixed Huffman codes. For rare inputs with a large number of distant matches, the pending buffer into which the compressed data is written can overwrite the distance symbol table which it overlays. That results in corrupted output due to invalid distances, and can result in out-of-bound accesses, crashing the application. The fix here combines the distance buffer and literal/length buffers into a single symbol buffer. Now three bytes of pending buffer space are opened up for each literal or length/distance pair consumed, instead of the previous two bytes. This assures that the pending buffer cannot overwrite the symbol table, since the maximum fixed code compressed length/distance is 31 bits, and since there are four bytes of pending space for every three bytes of symbol space.
Diffstat (limited to 'deflate_fast.c')
-rw-r--r--deflate_fast.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/deflate_fast.c b/deflate_fast.c
index 7c74dbe..a5861fe 100644
--- a/deflate_fast.c
+++ b/deflate_fast.c
@@ -114,7 +114,7 @@ ZLIB_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
FLUSH_BLOCK(s, 1);
return finish_done;
}
- if (s->last_lit)
+ if (s->sym_next)
FLUSH_BLOCK(s, 0);
return block_done;
}