[gimp/gimp-2-8] Bug 698859: PSD import filter: opening a PSD file causes...



commit 40512895d9e80c25175c6834e15da74bc1136ea6
Author: Massimo Valentini <mvalentini src gnome org>
Date:   Sun May 11 10:36:53 2014 +0200

    Bug 698859: PSD import filter: opening a PSD file causes...
    
    ...file-psd-load segfault.
    
    Fix loading of PSDs where the number of "end group" markers doesn't
    match the number of "start group" markers, which seems to be what is
    saved by Photoshop in some cases/versions/whatever.

 plug-ins/file-psd/psd-load.c |   55 +++++++++++++++++++++++++----------------
 1 files changed, 33 insertions(+), 22 deletions(-)
---
diff --git a/plug-ins/file-psd/psd-load.c b/plug-ins/file-psd/psd-load.c
index d9b4763..35adf82 100644
--- a/plug-ins/file-psd/psd-load.c
+++ b/plug-ins/file-psd/psd-load.c
@@ -1098,13 +1098,18 @@ add_layers (const gint32  image_id,
                 }
               else /* group-type == 1 || group_type == 2 */
                 {
-                  layer_id = g_array_index (parent_group_stack, gint32,
+                  if (parent_group_stack->len)
+                    {
+                      layer_id = g_array_index (parent_group_stack, gint32,
+                                                parent_group_stack->len-1);
+                      /* since the layers are stored in reverse, the group
+                         layer start marker actually means we're done with
+                         that layer group */
+                      g_array_remove_index (parent_group_stack,
                                             parent_group_stack->len-1);
-                  /* since the layers are stored in reverse, the group
-                     layer start marker actually means we're done with
-                     that layer group */
-                  g_array_remove_index (parent_group_stack,
-                                        parent_group_stack->len-1);
+                    }
+                  else
+                    layer_id = -1;
                 }
             }
 
@@ -1247,8 +1252,11 @@ add_layers (const gint32  image_id,
           l_y = 0;
           l_w = img_a->columns;
           l_h = img_a->rows;
-          parent_group_id = g_array_index (parent_group_stack, gint32,
-                                           parent_group_stack->len-1);
+          if (parent_group_stack->len > 0)
+            parent_group_id = g_array_index (parent_group_stack, gint32,
+                                             parent_group_stack->len-1);
+          else
+            parent_group_id = -1; /* root */
 
           IFDBG(3) g_debug ("Re-hash channel indices");
           for (cidx = 0; cidx < lyr_a[lidx]->num_channels; ++cidx)
@@ -1288,20 +1296,23 @@ add_layers (const gint32  image_id,
               else
                 {
                   IFDBG(2) g_debug ("End group layer id %d.", layer_id);
-                  drawable = gimp_drawable_get (layer_id);
-                  layer_mode = psd_to_gimp_blend_mode (lyr_a[lidx]->blend_mode);
-                  gimp_layer_set_mode (layer_id, layer_mode);
-                  gimp_layer_set_opacity (layer_id, 
-                                          lyr_a[lidx]->opacity * 100 / 255);
-                  gimp_item_set_name (drawable->drawable_id, lyr_a[lidx]->name);
-                  g_free (lyr_a[lidx]->name);
-                  gimp_item_set_visible (drawable->drawable_id,
-                                         lyr_a[lidx]->layer_flags.visible);
-                  if (lyr_a[lidx]->id)
-                    gimp_item_set_tattoo (drawable->drawable_id,
-                                          lyr_a[lidx]->id);
-                  gimp_drawable_flush (drawable);
-                  gimp_drawable_detach (drawable);
+                  if (layer_id != -1)
+                    {
+                      drawable = gimp_drawable_get (layer_id);
+                      layer_mode = psd_to_gimp_blend_mode (lyr_a[lidx]->blend_mode);
+                      gimp_layer_set_mode (layer_id, layer_mode);
+                      gimp_layer_set_opacity (layer_id,
+                                              lyr_a[lidx]->opacity * 100 / 255);
+                      gimp_item_set_name (drawable->drawable_id, lyr_a[lidx]->name);
+                      g_free (lyr_a[lidx]->name);
+                      gimp_item_set_visible (drawable->drawable_id,
+                                             lyr_a[lidx]->layer_flags.visible);
+                      if (lyr_a[lidx]->id)
+                        gimp_item_set_tattoo (drawable->drawable_id,
+                                              lyr_a[lidx]->id);
+                      gimp_drawable_flush (drawable);
+                      gimp_drawable_detach (drawable);
+                    }
                 }
             }
           else if (empty)


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