Skip to content

Commit

Permalink
Make sure we call inflateEnd when there is an error reading or compar…
Browse files Browse the repository at this point in the history
…ing the stream CRC (Issue #1070)
  • Loading branch information
michaelrsweet committed Oct 12, 2024
1 parent 3fe0aa4 commit fe04be5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
29 changes: 20 additions & 9 deletions cups/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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)
{
Expand Down

0 comments on commit fe04be5

Please sign in to comment.