]> 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:45:13 +0000 (11:45 -0400)
committerMichael R Sweet <msweet@msweet.org>
Sat, 12 Oct 2024 15:45:13 +0000 (11:45 -0400)
cups/file.c

index 0a6dce46cea88c12d0a599048a90dccc2605ba13..226b944606fca6a4c52310fc33006f1ecbf67d18 100644 (file)
@@ -2095,6 +2095,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
@@ -2105,6 +2106,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 = 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))
@@ -2119,6 +2126,7 @@ 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)
@@ -2131,11 +2139,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)
       {