Index: psd.c
===================================================================
RCS file: /cvs/gnome/gimp/plug-ins/common/psd.c,v
retrieving revision 1.51
diff -u -u -r1.51 psd.c
--- psd.c	12 Dec 2003 15:49:49 -0000	1.51
+++ psd.c	6 Jan 2004 20:07:40 -0000
@@ -1,5 +1,5 @@
 /*
- * PSD Plugin version 3.0.10
+ * PSD Plugin version 3.0.11
  * This GIMP plug-in is designed to load Adobe Photoshop(tm) files (.PSD)
  *
  * Adam D. Moss <adam@gimp.org> <adam@foxbox.org>
@@ -9,7 +9,7 @@
  *     about the image you tried to load.  Please don't send big PSD
  *     files to me without asking first.
  *
- *          Copyright (C) 1997-2003 Adam D. Moss
+ *          Copyright (C) 1997-2004 Adam D. Moss
  *          Copyright (C) 1996      Torsten Martinsen
  *
  * This program is free software; you can redistribute it and/or modify
@@ -35,6 +35,13 @@
 /*
  * Revision history:
  *
+ *  2004-01-06 / v3.0.12 / Adam D. Moss
+ *       Try to avoid 0-sized drawables (including channels) in all
+ *       circumstances under GIMP 2.
+ *
+ *  2004-01-01 / v3.0.11 / Daniel Rogers <dsrogers@phaseveloctiy.org>
+ *       GIMP crashes on 0x0 layers, so we skip them.
+ *       
  *  2003-11-27 / v3.0.10 / Adam D. Moss
  *       GIMP 1.3/2.0 needs its layer/channel names to be UTF8 or it
  *       fails wackily, so convert the strings from the PSD file to
@@ -1565,6 +1572,13 @@
   IFDBG printf("Extracting primary channel data (%d channels)\n"
 	 "\tand %d auxiliary channels.\n", gimpstep, psstep-gimpstep);
 
+  /* gimp doesn't like 0 width/height drawables. */
+  if ((width == 0) || (height == 0))
+    {
+      IFDBG printf("(bad channel dimensions -- skipping)");
+      return;
+    }
+
   primary_data = g_malloc(width * height * gimpstep);
   {
     int pix,chan;
@@ -1637,6 +1651,13 @@
 
   IFDBG printf("Extracting %d/%d auxiliary channels.\n", num_wanted, psstep);
 
+  /* gimp doesn't like 0 width/height drawables. */
+  if ((width == 0) || (height == 0))
+    {
+      IFDBG printf("(bad channel dimensions -- skipping)");
+      return;
+    }
+
   aux_data = g_malloc(width * height);
   {
     int pix, chan;
@@ -1774,9 +1795,20 @@
 	  gint numc;
 	  guchar* merged_data = NULL;
 	  PSDlayer *layer = psd_image.layer + lnum;
-
+	  
+	  /*
+	   * since ps supports sloppy bounding boxes it is possible to
+	   * have a 0x0 or Xx0 or 0xY layer.  Gimp doesn't support a
+	   * 0x0 layer so we will just skip these.  We might be able
+	   * to do something better here.
+	   */
+	  if ((layer->width == 0) || (layer->height == 0))
+	    {
+	      IFDBG printf("(bad layer dimensions -- skipping)");
+	      continue;
+	    }
 	  numc = layer->num_channels;
-
+	  
 	  IFDBG printf("Hey, it's a LAYER with %d channels!\n", numc);
 
 	  switch (gimagetype)
@@ -2105,6 +2137,13 @@
 
       if (!want_aux)
 	{
+	  /* gimp doesn't like 0 width/height drawables. */
+	  if ((PSDheader.columns == 0) || (PSDheader.rows == 0))
+	    {
+	      IFDBG printf("(bad psd2-style image dimensions -- skipping)");
+	      goto finish_up;
+	    }
+
 	  image_ID = gimp_image_new (PSDheader.columns, PSDheader.rows,
 				     psd_type_to_gimp_base_type(imagetype));
 	  gimp_image_set_filename (image_ID, name);
