[gimp] plug-ins: PSD layer size validation only for "normal" layers.



commit 0de02a5b2d0736c70482d83236d2701c99450f98
Author: Jacob Boerema <jgboerema gmail com>
Date:   Mon May 17 18:37:06 2021 -0400

    plug-ins: PSD layer size validation only for "normal" layers.
    
    Apparently layer height or width can be negative for certain
    PSD layers that have the irrelevant flag set.
    
    We move those checks down until after we have read that
    flag and only validate if the irrelevant flag is not set.

 plug-ins/file-psd/psd-load.c | 60 +++++++++++++++++++++++---------------------
 1 file changed, 32 insertions(+), 28 deletions(-)
---
diff --git a/plug-ins/file-psd/psd-load.c b/plug-ins/file-psd/psd-load.c
index 41c09cbb73..8151d0c27e 100644
--- a/plug-ins/file-psd/psd-load.c
+++ b/plug-ins/file-psd/psd-load.c
@@ -578,33 +578,6 @@ read_layer_info (PSDimage      *img_a,
                            lyr_a[lidx]->num_channels);
               return NULL;
             }
-          if (lyr_a[lidx]->bottom < lyr_a[lidx]->top ||
-              lyr_a[lidx]->bottom - lyr_a[lidx]->top > GIMP_MAX_IMAGE_SIZE)
-            {
-              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                           _("Unsupported or invalid layer height: %d"),
-                           lyr_a[lidx]->bottom - lyr_a[lidx]->top);
-              return NULL;
-            }
-          if (lyr_a[lidx]->right < lyr_a[lidx]->left ||
-              lyr_a[lidx]->right - lyr_a[lidx]->left > GIMP_MAX_IMAGE_SIZE)
-            {
-              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                           _("Unsupported or invalid layer width: %d"),
-                           lyr_a[lidx]->right - lyr_a[lidx]->left);
-              return NULL;
-            }
-
-          if ((lyr_a[lidx]->right - lyr_a[lidx]->left) >
-              G_MAXINT32 / MAX (lyr_a[lidx]->bottom - lyr_a[lidx]->top, 1))
-            {
-              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                           _("Unsupported or invalid layer size: %dx%d"),
-                           lyr_a[lidx]->right - lyr_a[lidx]->left,
-                           lyr_a[lidx]->bottom - lyr_a[lidx]->top);
-              return NULL;
-            }
-
           IFDBG(2) g_debug ("Layer %d, Coords %d %d %d %d, channels %d, ",
                             lidx, lyr_a[lidx]->left, lyr_a[lidx]->top,
                             lyr_a[lidx]->right, lyr_a[lidx]->bottom,
@@ -671,7 +644,38 @@ read_layer_info (PSDimage      *img_a,
                             lyr_a[lidx]->layer_flags.trans_prot,
                             lyr_a[lidx]->layer_flags.visible,
                             lyr_a[lidx]->layer_flags.irrelevant);
-          IFDBG(3) g_debug ("Remaining length %" G_GOFFSET_FORMAT, block_rem);
+          IFDBG(3) g_debug ("Offset: %" G_GOFFSET_FORMAT ", Remaining length %" G_GSIZE_FORMAT,
+                            PSD_TELL(input), block_rem);
+
+          if (! lyr_a[lidx]->layer_flags.irrelevant)
+            {
+              if (lyr_a[lidx]->bottom < lyr_a[lidx]->top ||
+                  lyr_a[lidx]->bottom - lyr_a[lidx]->top > GIMP_MAX_IMAGE_SIZE)
+                {
+                  g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                              _("Unsupported or invalid layer height: %d"),
+                              lyr_a[lidx]->bottom - lyr_a[lidx]->top);
+                  return NULL;
+                }
+              if (lyr_a[lidx]->right < lyr_a[lidx]->left ||
+                  lyr_a[lidx]->right - lyr_a[lidx]->left > GIMP_MAX_IMAGE_SIZE)
+                {
+                  g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                              _("Unsupported or invalid layer width: %d"),
+                              lyr_a[lidx]->right - lyr_a[lidx]->left);
+                  return NULL;
+                }
+
+              if ((lyr_a[lidx]->right - lyr_a[lidx]->left) >
+                  G_MAXINT32 / MAX (lyr_a[lidx]->bottom - lyr_a[lidx]->top, 1))
+                {
+                  g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                              _("Unsupported or invalid layer size: %dx%d"),
+                              lyr_a[lidx]->right - lyr_a[lidx]->left,
+                              lyr_a[lidx]->bottom - lyr_a[lidx]->top);
+                  return NULL;
+                }
+            }
 
           /* Layer mask data */
           if (psd_read (input, &block_len, 4, error) < 4)


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