diff options
author | Ilya Leoshkevich <iii@linux.ibm.com> | 2021-03-17 01:14:41 +0100 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2021-03-17 10:08:32 +0100 |
commit | ff0ab283f0b50e909e9bbb3620f3f401f2eb1491 (patch) | |
tree | 66418336c5a03ff9126f2bc5eae186a74fac2c87 /deflate_quick.c | |
parent | ac18b0c35c8cf56bcc2531e100372f654390923b (diff) |
Fix block_open handling in deflate_quick()
The attached test fails with "inflate() failed", because the deflate
stream that it produces ends up being corrupted. Bisect points to the
commit e7bb6db09a18 ("Replace hash_bits, hash_size and hash_mask with
defines."), but it's most likely a coincidence.
In any case, the reason is that if we happen to simultaneously exhaust
all the buffers (in, out and bi), we return finish_started without
writing the end of block symbol, which will never happen afterwards.
Fix by adding another check to the tricky condition: if we are in the
middle of a block, return need_more instead of finish_started.
Diffstat (limited to 'deflate_quick.c')
-rw-r--r-- | deflate_quick.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/deflate_quick.c b/deflate_quick.c index d749b3a..b439743 100644 --- a/deflate_quick.c +++ b/deflate_quick.c @@ -65,7 +65,7 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) { if (UNLIKELY(s->pending + ((BIT_BUF_SIZE + 7) >> 3) >= s->pending_buf_size)) { flush_pending(s->strm); if (s->strm->avail_out == 0) { - return (last && s->strm->avail_in == 0 && s->bi_valid == 0) ? finish_started : need_more; + return (last && s->strm->avail_in == 0 && s->bi_valid == 0 && s->block_open == 0) ? finish_started : need_more; } } |