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 #91)
  • Loading branch information
michaelrsweet committed Oct 12, 2024
1 parent 07513bb commit 83562f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes in libcups
libcups v3.0.0 (YYYY-MM-DD)
---------------------------

- Fixed a compressed file error handling bug (Issue #91)
- Fixed the default User-Agent string sent in requests.
- Fixed a recursion issue in `ippReadIO`.

Expand Down
13 changes: 8 additions & 5 deletions cups/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,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
Expand All @@ -1692,6 +1693,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 = false;

// 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 @@ -1704,6 +1711,7 @@ cups_fill(cups_file_t *fp) // I - CUPS file
}
}

// Calculate and compare the CRC...
tcrc = ((((((uLong)trailer[3] << 8) | (uLong)trailer[2]) << 8) | (uLong)trailer[1]) << 8) | (uLong)trailer[0];

if (tcrc != fp->crc)
Expand All @@ -1714,11 +1722,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 = false;
}
else if (status < Z_OK)
{
Expand Down
2 changes: 1 addition & 1 deletion pdfio
Submodule pdfio updated 7 files
+0 −1 CHANGES.md
+2 −129 doc/pdfio.3
+6 −109 doc/pdfio.html
+1 −68 doc/pdfio.md
+3 −29 pdfio-object.c
+3 −0 pdfio-stream.c
+0 −8 ttf.c

0 comments on commit 83562f7

Please sign in to comment.