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