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