8ca2e9
diff --git a/tools/gif2tiff.c b/tools/gif2tiff.c
8ca2e9
index 2786974..9262573 100644
8ca2e9
--- a/tools/gif2tiff.c
8ca2e9
+++ b/tools/gif2tiff.c
8ca2e9
@@ -276,6 +276,10 @@ readgifimage(char* mode)
8ca2e9
         fprintf(stderr, "no colormap present for image\n");
8ca2e9
         return (0);
8ca2e9
     }
8ca2e9
+    if (width == 0 || height == 0) {
8ca2e9
+        fprintf(stderr, "Invalid value of width or height\n");
8ca2e9
+        return(0);
8ca2e9
+    }
8ca2e9
     if ((raster = (unsigned char*) _TIFFmalloc(width*height+EXTRAFUDGE)) == NULL) {
8ca2e9
         fprintf(stderr, "not enough memory for image\n");
8ca2e9
         return (0);
8ca2e9
@@ -402,6 +406,10 @@ process(register int code, unsigned char** fill)
8ca2e9
             fprintf(stderr, "bad input: code=%d is larger than clear=%d\n",code, clear);
8ca2e9
             return 0;
8ca2e9
         }
8ca2e9
+        if (*fill >= raster + width*height) {
8ca2e9
+            fprintf(stderr, "raster full before eoi code\n");
8ca2e9
+            return 0;
8ca2e9
+        }
8ca2e9
 	*(*fill)++ = suffix[code];
8ca2e9
 	firstchar = oldcode = code;
8ca2e9
 	return 1;
8ca2e9
@@ -432,6 +440,10 @@ process(register int code, unsigned char** fill)
8ca2e9
     }
8ca2e9
     oldcode = incode;
8ca2e9
     do {
8ca2e9
+        if (*fill >= raster + width*height) {
8ca2e9
+            fprintf(stderr, "raster full before eoi code\n");
8ca2e9
+            return 0;
8ca2e9
+        }
8ca2e9
 	*(*fill)++ = *--stackp;
8ca2e9
     } while (stackp > stack);
8ca2e9
     return 1;