From 7a2d383ee59a90f41d482476edb909165ea9565d Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Sat, 12 Oct 2024 11:45:13 -0400 Subject: [PATCH] Make sure we call inflateEnd when there is an error reading or comparing the stream CRC (Issue #1070) --- cups/file.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cups/file.c b/cups/file.c index 0a6dce46c..226b94460 100644 --- a/cups/file.c +++ b/cups/file.c @@ -2095,6 +2095,7 @@ cups_fill(cups_file_t *fp) // I - CUPS file if (fp->stream.avail_in > 0) { + // Get the first N trailer bytes from the inflate stream... if (fp->stream.avail_in > sizeof(trailer)) tbytes = (ssize_t)sizeof(trailer); else @@ -2105,6 +2106,12 @@ cups_fill(cups_file_t *fp) // I - CUPS file fp->stream.avail_in -= (size_t)tbytes; } + // Reset the compressed flag so that we re-read the file header... + inflateEnd(&fp->stream); + + fp->compressed = 0; + + // Get any remaining trailer bytes... if (tbytes < (ssize_t)sizeof(trailer)) { if (read(fp->fd, trailer + tbytes, sizeof(trailer) - (size_t)tbytes) < ((ssize_t)sizeof(trailer) - tbytes)) @@ -2119,6 +2126,7 @@ cups_fill(cups_file_t *fp) // I - CUPS file } } + // Calculate and compare the CRC... tcrc = ((uLong)trailer[3] << 24) | ((uLong)trailer[2] << 16) | ((uLong)trailer[1] << 8) | ((uLong)trailer[0]); if (tcrc != fp->crc) @@ -2131,11 +2139,6 @@ cups_fill(cups_file_t *fp) // I - CUPS file return (-1); } - - // Otherwise, reset the compressed flag so that we re-read the file header... - inflateEnd(&fp->stream); - - fp->compressed = 0; } else if (status < Z_OK) {