Skip to content

Commit 1c0a0af

Browse files
mzaslonkakpm00
authored andcommitted
lib/zlib: DFLTCC deflate does not write all available bits for Z_NO_FLUSH
DFLTCC deflate with Z_NO_FLUSH might generate a corrupted stream when the output buffer is not large enough to fit all the deflate output at once. The problem takes place on closing the deflate block since flush_pending() might leave some output bits not written. Similar problem for software deflate with Z_BLOCK flush option (not supported by kernel zlib deflate) has been fixed a while ago in userspace zlib but the fix never got to the kernel. Now flush_pending() flushes the bit buffer before copying out the byte buffer, in order to really flush as much as possible. Currently there are no users of DFLTCC deflate with Z_NO_FLUSH option in the kernel so the problem remained hidden for a while. This commit is based on the old zlib commit: madler/zlib@0b828b4 Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Mikhail Zaslonko <[email protected]> Acked-by: Ilya Leoshkevich <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Vasily Gorbik <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 3f98c9a commit 1c0a0af

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/zlib_deflate/defutil.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,11 @@ static inline void flush_pending(
420420
z_streamp strm
421421
)
422422
{
423+
unsigned len;
423424
deflate_state *s = (deflate_state *) strm->state;
424-
unsigned len = s->pending;
425425

426+
bi_flush(s);
427+
len = s->pending;
426428
if (len > strm->avail_out) len = strm->avail_out;
427429
if (len == 0) return;
428430

0 commit comments

Comments
 (0)