--- libgd-2.1.0/src/gd_gif_in.c.orig 2013-07-04 16:17:44.855925413 +0200 +++ libgd-2.1.0/src/gd_gif_in.c 2013-07-04 16:35:04.025881804 +0200 @@ -498,15 +498,16 @@ 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) { + if((count != 0) || (max_count < 0)) { return -2; } }