d00bc4
diff --git a/tools/gif2tiff.c b/tools/gif2tiff.c
d00bc4
index 375b152..2731273 100644
d00bc4
--- a/tools/gif2tiff.c
d00bc4
+++ b/tools/gif2tiff.c
d00bc4
@@ -402,6 +402,10 @@ process(register int code, unsigned char** fill)
d00bc4
     }
d00bc4
 
d00bc4
     if (oldcode == -1) {
d00bc4
+        if (code >= clear) {
d00bc4
+            fprintf(stderr, "bad input: code=%d is larger than clear=%d\n",code, clear);
d00bc4
+            return 0;
d00bc4
+        }
d00bc4
 	*(*fill)++ = suffix[code];
d00bc4
 	firstchar = oldcode = code;
d00bc4
 	return 1;