diff --git a/CHANGES.md b/CHANGES.md index b554e5253..d7e1f26e9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ CHANGES - OpenPrinting CUPS Changes in CUPS v2.4.12 (YYYY-MM-DD) ------------------------------------ +- Fixed a compressed file error handling bug (Issue #1070) - Fixed the default User-Agent string. - Fixed a recursion issue in `ippReadIO`. diff --git a/cups/file.c b/cups/file.c index 95054f3c8..7f4870633 100644 --- a/cups/file.c +++ b/cups/file.c @@ -2486,6 +2486,10 @@ 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 @@ -2496,6 +2500,18 @@ 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)) @@ -2513,6 +2529,10 @@ 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) @@ -2528,15 +2548,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) {