]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Make sure we call inflateEnd when there is an error reading or comparing the stream...
authorMichael R Sweet <msweet@msweet.org>
Sat, 12 Oct 2024 15:47:49 +0000 (11:47 -0400)
committerMichael R Sweet <msweet@msweet.org>
Sat, 12 Oct 2024 15:47:49 +0000 (11:47 -0400)
CHANGES.md
cups/file.c

index b554e5253a62fd76eb32df676802fe22fbc4859e..d7e1f26e9ecb3c336e997d5446baf17fe2ca3d73 100644 (file)
@@ -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`.
 
index 95054f3c8b8f11a691c7e3904b50ed8f17cb3614..7f487063357a2ce817b9f0ab26afddc97b3bf78d 100644 (file)
@@ -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)
       {