Skip to content

Commit cbf1254

Browse files
mzaslonkakpm00
authored andcommitted
lib/zlib: DFLTCC not writing header bits when avail_out == 0
This commit is based on: zlib-ng/zlib-ng@ce409c6 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 0dbae46 commit cbf1254

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/zlib_dfltcc/dfltcc_deflate.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,18 @@ int dfltcc_deflate(
170170
param->bcf = 0;
171171
dfltcc_state->block_threshold =
172172
strm->total_in + dfltcc_state->block_size;
173-
if (strm->avail_out == 0) {
174-
*result = need_more;
175-
return 1;
176-
}
177173
}
178174
}
179175

176+
/* No space for compressed data. If we proceed, dfltcc_cmpr() will return
177+
* DFLTCC_CC_OP1_TOO_SHORT without buffering header bits, but we will still
178+
* set BCF=1, which is wrong. Avoid complications and return early.
179+
*/
180+
if (strm->avail_out == 0) {
181+
*result = need_more;
182+
return 1;
183+
}
184+
180185
/* The caller gave us too much data. Pass only one block worth of
181186
* uncompressed data to DFLTCC and mask the rest, so that on the next
182187
* iteration we start a new block.

0 commit comments

Comments
 (0)