Skip to content

Commit 195c5ad

Browse files
mzaslonkakpm00
authored andcommitted
lib/zlib: fix DFLTCC not flushing EOBS when creating raw streams
This commit is based on: zlib-ng/zlib-ng@ca99a88 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 9a54933 commit 195c5ad

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/zlib_deflate/deflate.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,17 +451,24 @@ int zlib_deflate(
451451
Assert(strm->avail_out > 0, "bug2");
452452

453453
if (flush != Z_FINISH) return Z_OK;
454-
if (s->noheader) return Z_STREAM_END;
455454

456-
/* Write the zlib trailer (adler32) */
457-
putShortMSB(s, (uInt)(strm->adler >> 16));
458-
putShortMSB(s, (uInt)(strm->adler & 0xffff));
455+
if (!s->noheader) {
456+
/* Write zlib trailer (adler32) */
457+
putShortMSB(s, (uInt)(strm->adler >> 16));
458+
putShortMSB(s, (uInt)(strm->adler & 0xffff));
459+
}
459460
flush_pending(strm);
460461
/* If avail_out is zero, the application will call deflate again
461462
* to flush the rest.
462463
*/
463-
s->noheader = -1; /* write the trailer only once! */
464-
return s->pending != 0 ? Z_OK : Z_STREAM_END;
464+
if (!s->noheader) {
465+
s->noheader = -1; /* write the trailer only once! */
466+
}
467+
if (s->pending == 0) {
468+
Assert(s->bi_valid == 0, "bi_buf not flushed");
469+
return Z_STREAM_END;
470+
}
471+
return Z_OK;
465472
}
466473

467474
/* ========================================================================= */

0 commit comments

Comments
 (0)