diff options
author | Ilya Leoshkevich iii@linux.ibm.com <iii@linux.ibm.com> | 2021-03-15 20:15:47 +0100 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2021-03-16 12:21:30 +0100 |
commit | 04ae6d8b19ad32adf66138fb84c62fc7bf310334 (patch) | |
tree | fe46bf2f2abfded4741d26eb8b83b02b8338c1eb /deflate_quick.c | |
parent | 052b9fcb1b4df1321c6fbe5fccc895beeda3c903 (diff) |
Fix bi_valid handling in deflate_quick()
The attached test started failing after commit ad89d5131b29 ("Don't
write end of last block when returning finish_started."): either with
"bi_buf not flushed" message in debug builds, or by producing corrupted
output in release builds.
The problem is that we must not return finish_started when bi_buf is
not empty, because the bits there will be lost. Fix by checking that
bi_valid is not 0.
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 268cce8..d749b3a 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) ? finish_started : need_more; + return (last && s->strm->avail_in == 0 && s->bi_valid == 0) ? finish_started : need_more; } } |