[gimp/gimp-2-10] plug-ins: don't try to read tiff pages with an invalid directory.



commit 334e905ae21e6f4d3b7e13fdb251abae9cbe256f
Author: Jacob Boerema <jgboerema gmail com>
Date:   Sat Oct 24 13:44:39 2020 -0400

    plug-ins: don't try to read tiff pages with an invalid directory.
    
    We didn't check whether TIFFSetDirectory succeeded nor did
    we check TIFFReadScanline for failure which can cause
    unresponsiveness.
    
    We will not try to read a tiff page if setting its directory fails
    and we will stop reading a page if reading scanline fails.
    
    (cherry picked from commit e4514567f9ff675271670f28a3cf523e49832ff3)

 plug-ins/file-tiff/file-tiff-load.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/plug-ins/file-tiff/file-tiff-load.c b/plug-ins/file-tiff/file-tiff-load.c
index a5e878ec37..dc458c3c25 100644
--- a/plug-ins/file-tiff/file-tiff-load.c
+++ b/plug-ins/file-tiff/file-tiff-load.c
@@ -341,7 +341,12 @@ load_image (GFile        *file,
       TiffSaveVals      save_vals;
       const gchar      *name;
 
-      TIFFSetDirectory (tif, pages.pages[li]);
+      if (TIFFSetDirectory (tif, pages.pages[li]) == 0)
+        {
+          g_message (_("Couldn't read page %d of %d. Image might be corrupt.\n"),
+                     li+1, pages.n_pages);
+          continue;
+        }
       ilayer = pages.pages[li];
 
       gimp_progress_update (0.0);
@@ -1573,8 +1578,14 @@ load_contiguous (TIFF        *tif,
 
           if (TIFFIsTiled (tif))
             TIFFReadTile (tif, buffer, x, y, 0, 0);
-          else
-            TIFFReadScanline (tif, buffer, y, 0);
+          else if (TIFFReadScanline (tif, buffer, y, 0) == -1)
+            {
+              /* Error reading scanline, stop loading */
+              g_printerr ("Reading scanline failed. Image may be corrupt at line %d.\n", y);
+              g_free (buffer);
+              g_free (bw_buffer);
+              return;
+            }
 
           cols = MIN (image_width  - x, tile_width);
           rows = MIN (image_height - y, tile_height);
@@ -1742,8 +1753,14 @@ load_separate (TIFF        *tif,
 
                   if (TIFFIsTiled (tif))
                     TIFFReadTile (tif, buffer, x, y, 0, compindex);
-                  else
-                    TIFFReadScanline (tif, buffer, y, compindex);
+                  else if (TIFFReadScanline (tif, buffer, y, compindex) == -1)
+                    {
+                      /* Error reading scanline, stop loading */
+                      g_printerr ("Reading scanline failed. Image may be corrupt at line %d.\n", y);
+                      g_free (buffer);
+                      g_free (bw_buffer);
+                      return;
+                    }
 
                   cols = MIN (image_width  - x, tile_width);
                   rows = MIN (image_height - y, tile_height);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]