Skip to content

Commit 83562f7

Browse files
committed
Make sure we call inflateEnd when there is an error reading or comparing the
stream CRC (Issue #91)
1 parent 07513bb commit 83562f7

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changes in libcups
44
libcups v3.0.0 (YYYY-MM-DD)
55
---------------------------
66

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

cups/file.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,7 @@ cups_fill(cups_file_t *fp) // I - CUPS file
16821682

16831683
if (fp->stream.avail_in > 0)
16841684
{
1685+
// Get the first N trailer bytes from the inflate stream...
16851686
if (fp->stream.avail_in > sizeof(trailer))
16861687
tbytes = (ssize_t)sizeof(trailer);
16871688
else
@@ -1692,6 +1693,12 @@ cups_fill(cups_file_t *fp) // I - CUPS file
16921693
fp->stream.avail_in -= (size_t)tbytes;
16931694
}
16941695

1696+
// Reset the compressed flag so that we re-read the file header...
1697+
inflateEnd(&fp->stream);
1698+
1699+
fp->compressed = false;
1700+
1701+
// Get any remaining trailer bytes...
16951702
if (tbytes < (ssize_t)sizeof(trailer))
16961703
{
16971704
if (read(fp->fd, trailer + tbytes, sizeof(trailer) - (size_t)tbytes) < ((ssize_t)sizeof(trailer) - tbytes))
@@ -1704,6 +1711,7 @@ cups_fill(cups_file_t *fp) // I - CUPS file
17041711
}
17051712
}
17061713

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

17091717
if (tcrc != fp->crc)
@@ -1714,11 +1722,6 @@ cups_fill(cups_file_t *fp) // I - CUPS file
17141722

17151723
return (-1);
17161724
}
1717-
1718-
// Otherwise, reset the compressed flag so that we re-read the file header...
1719-
inflateEnd(&fp->stream);
1720-
1721-
fp->compressed = false;
17221725
}
17231726
else if (status < Z_OK)
17241727
{

0 commit comments

Comments
 (0)