Index: psd.c
===================================================================
RCS file: /cvs/gnome/gimp/plug-ins/common/psd.c,v
retrieving revision 1.31
diff -u -r1.31 psd.c
--- psd.c	23 Aug 2000 19:13:41 -0000	1.31
+++ psd.c	16 Jun 2003 15:33:55 -0000
@@ -131,7 +131,7 @@
 /* *** USER DEFINES *** */
 
 /* set to TRUE if you want debugging, FALSE otherwise */
-#define PSD_DEBUG FALSE
+#define PSD_DEBUG TRUE
 
 /* the max number of layers that this plugin should try to load */
 #define MAX_LAYERS 100
@@ -2379,8 +2379,8 @@
 
     while (upremain > 0)
       {
-	(*offset)++;
 	n = (int) getguchar(fd, "packbits1");
+	(*offset)++;
 
 	if (n >= 128)
 	  n -= 256;
@@ -2395,8 +2395,10 @@
 	    (*offset)++;
 	    for (; n > 0; --n)
 	      {
-		*dst = b;
-		dst ++;
+		if (upremain >= 0) {
+		  *dst = b;
+		  dst ++;
+		}
 		upremain--;
 	      }
 	  }
@@ -2404,9 +2406,12 @@
 	  {		/* copy next n+1 guchars literally */
 	    for (b = ++n; b > 0; --b)
 	      {
-		*dst = getguchar(fd, "packbits3");;
+		const guchar c = getguchar(fd, "packbits3");;
+		if (upremain >= 0) {
+		  *dst = c;
+		  dst ++;
+		}
 		(*offset)++;
-		dst ++;
 		upremain--;
 	      }
 	    /*	    upremain -= n;*/
