[gimp] plug-ins: fix export of multi layer image as psd



commit 3425212a3fa30ad6ef2fbcd85f5e8611206a1aad
Author: Jacob Boerema <jgboerema gmail com>
Date:   Thu Nov 11 18:30:15 2021 -0500

    plug-ins: fix export of multi layer image as psd
    
    Due to starting with the highest index we were referencing layer data
    out of bounds.
    We need to decrease i with 1 before using it as index into the channel data
    for the correct layer.
    This caused a crash when exporting multi layer images.

 plug-ins/file-psd/psd-save.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/plug-ins/file-psd/psd-save.c b/plug-ins/file-psd/psd-save.c
index 5603df0230..7c4f2d4142 100644
--- a/plug-ins/file-psd/psd-save.c
+++ b/plug-ins/file-psd/psd-save.c
@@ -1112,7 +1112,7 @@ save_layer_and_mask (GOutputStream  *output,
                    "\t\tY offset: %d\n"
                    "\t\tWidth: %d\n"
                    "\t\tHeight: %d\n",
-                   i, type, offset_x, offset_y,
+                   i-1, type, offset_x, offset_y,
                    layerWidth, layerHeight);
         }
 
@@ -1133,7 +1133,7 @@ save_layer_and_mask (GOutputStream  *output,
 
       /* Create second array dimension (layers, channels) */
 
-      ChannelLengthPos[i] = g_new (goffset, nChannelsLayer);
+      ChannelLengthPos[i-1] = g_new (goffset, nChannelsLayer);
 
       /* Try with gimp_drawable_get_bpp() */
 
@@ -1152,7 +1152,7 @@ save_layer_and_mask (GOutputStream  *output,
           /* Write the length assuming no compression.  In case there is,
              will modify it later when writing data.  */
 
-          ChannelLengthPos[i][j] = g_seekable_tell (G_SEEKABLE (output));
+          ChannelLengthPos[i-1][j] = g_seekable_tell (G_SEEKABLE (output));
           ChanSize = sizeof (gint16) + (layerWidth * layerHeight * bpc);
 
           write_gint32 (output, ChanSize, "Channel Size");
@@ -1324,10 +1324,10 @@ save_layer_and_mask (GOutputStream  *output,
 
       gimp_progress_update ((PSDImageData.nLayers - i - 1.0) / (PSDImageData.nLayers + 1.0));
 
-      IFDBG(1) g_debug ("\t\tWriting pixel data for layer slot %d", i);
-      write_pixel_data (output, GIMP_DRAWABLE (psd_layer->layer), ChannelLengthPos[i], 0,
+      IFDBG(1) g_debug ("\t\tWriting pixel data for layer slot %d", i-1);
+      write_pixel_data (output, GIMP_DRAWABLE (psd_layer->layer), ChannelLengthPos[i-1], 0,
                         psd_layer->type != PSD_LAYER_TYPE_GROUP_END);
-      g_free (ChannelLengthPos[i]);
+      g_free (ChannelLengthPos[i-1]);
     }
 
   gimp_progress_update (PSDImageData.nLayers / (PSDImageData.nLayers + 1.0));


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