7b70ea
diff -up gd-2.0.35/gd_gif_in.c.loop gd-2.0.35/gd_gif_in.c
7b70ea
--- gd-2.0.35/gd_gif_in.c.loop	2007-06-14 15:51:41.000000000 -0400
7b70ea
+++ gd-2.0.35/gd_gif_in.c	2008-07-21 11:20:25.000000000 -0400
7b70ea
@@ -453,16 +453,17 @@ LWZReadByte_(gdIOCtx *fd, LZW_STATIC_DAT
7b70ea
                        return sd->firstcode;
7b70ea
                } else if (code == sd->end_code) {
jkudrnac 98cc7b
                        int             count;
7b70ea
+                       int             max_count = 1024;
jkudrnac 98cc7b
                        unsigned char   buf[260];
jkudrnac 98cc7b
 
jkudrnac 98cc7b
                        if (*ZeroDataBlockP)
jkudrnac 98cc7b
                                return -2;
jkudrnac 98cc7b
 
jkudrnac 98cc7b
-                       while ((count = GetDataBlock(fd, buf, ZeroDataBlockP)) > 0)
jkudrnac 98cc7b
+                       while ((count = GetDataBlock(fd, buf, ZeroDataBlockP)) > 0 && --max_count >= 0 )
jkudrnac 98cc7b
                                ;
jkudrnac 98cc7b
 
jkudrnac 98cc7b
-                       if (count != 0)
jkudrnac 98cc7b
-                       return -2;
jkudrnac 98cc7b
+                       if (count != 0 || max_count < 0 )
7b70ea
+                               return -2;
jkudrnac 98cc7b
                }
jkudrnac 98cc7b
 
jkudrnac 98cc7b
                incode = code;