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/20230126131428.1222214-6-zaslonko@linux.ibm.com Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com> Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 0dbae46 commit cbf1254

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

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)