Skip to content

Commit

Permalink
lib/zlib: DFLTCC not writing header bits when avail_out == 0
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mzaslonk authored and akpm00 committed Feb 3, 2023
1 parent 0dbae46 commit cbf1254
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/zlib_dfltcc/dfltcc_deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,18 @@ int dfltcc_deflate(
param->bcf = 0;
dfltcc_state->block_threshold =
strm->total_in + dfltcc_state->block_size;
if (strm->avail_out == 0) {
*result = need_more;
return 1;
}
}
}

/* No space for compressed data. If we proceed, dfltcc_cmpr() will return
* DFLTCC_CC_OP1_TOO_SHORT without buffering header bits, but we will still
* set BCF=1, which is wrong. Avoid complications and return early.
*/
if (strm->avail_out == 0) {
*result = need_more;
return 1;
}

/* The caller gave us too much data. Pass only one block worth of
* uncompressed data to DFLTCC and mask the rest, so that on the next
* iteration we start a new block.
Expand Down

0 comments on commit cbf1254

Please sign in to comment.