[gimp/gimp-2-10] plug-ins: check for invalid resolution when loading TIFF image



commit 9829679e6de22f1b42a77ef1e9d6fea6e308efa8
Author: Jacob Boerema <jgboerema gmail com>
Date:   Mon Aug 22 22:21:33 2022 -0400

    plug-ins: check for invalid resolution when loading TIFF image
    
    This is essentially the same check as done in gimp_image_set_resolution,
    but doing it here means we can load the image instead of throwing an
    error.
    
    We still need to get replacement xres and yres values, because these are
    used to compute layer_offset_x_pixel and layer_offset_y_pixel.
    
    (cherry picked from commit ced071a8eeb584595de9d26d3a1d8dea87e99ba8)

 plug-ins/file-tiff/file-tiff-load.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/plug-ins/file-tiff/file-tiff-load.c b/plug-ins/file-tiff/file-tiff-load.c
index 2b876bf9b6..bb4e79d680 100644
--- a/plug-ins/file-tiff/file-tiff-load.c
+++ b/plug-ins/file-tiff/file-tiff-load.c
@@ -1340,11 +1340,25 @@ load_image (GFile        *file,
              */
             if (read_unit != RESUNIT_NONE)
               {
-                gimp_image_set_resolution (*image, xres, yres);
-                if (unit != GIMP_UNIT_PIXEL)
-                  gimp_image_set_unit (*image, unit);
+                if (! isfinite (xres) ||
+                    xres < GIMP_MIN_RESOLUTION || xres > GIMP_MAX_RESOLUTION ||
+                    ! isfinite (yres) ||
+                    yres < GIMP_MIN_RESOLUTION || yres > GIMP_MAX_RESOLUTION)
+                  {
+                    g_message (_("Invalid image resolution info, using default"));
+                    /* We need valid xres and yres for computing
+                     * layer_offset_x_pixel and layer_offset_y_pixel.
+                     */
+                    gimp_image_get_resolution (*image, &xres, &yres);
+                  }
+                else
+                  {
+                    gimp_image_set_resolution (*image, xres, yres);
+                    if (unit != GIMP_UNIT_PIXEL)
+                      gimp_image_set_unit (*image, unit);
 
-                *resolution_loaded = TRUE;
+                    *resolution_loaded = TRUE;
+                  }
               }
           }
 


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