diff --git gd-2.0.33/gd_gif_in.c b/BUILD/gd-2.0.33/gd_gif_in.c index 6301c21..7668169 100644 --- gd-2.0.33/gd_gif_in.c +++ gd-2.0.33/gd_gif_in.c @@ -136,6 +136,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromGifCtx(gdIOCtxPtr fd) /* 2.0.28: threadsafe storage */ int ZeroDataBlock = FALSE; int maxcount = 1024; + int haveGlobalColormap; gdImagePtr im = 0; if (! ReadOK(fd,buf,6)) { @@ -165,11 +166,12 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromGifCtx(gdIOCtxPtr fd) screen_width = imw = LM_to_uint(buf[0],buf[1]); screen_height = imh = LM_to_uint(buf[2],buf[3]); - if (BitSet(buf[4], LOCALCOLORMAP)) { /* Global Colormap */ - if (ReadColorMap(fd, BitPixel, ColorMap)) { - return 0; - } - } + haveGlobalColormap = BitSet(buf[4], LOCALCOLORMAP); /* Global Colormap */ + if (haveGlobalColormap) { + if (ReadColorMap(fd, BitPixel, ColorMap)) { + return 0; + } + } for (;;) { int top, left; int width, height; @@ -220,13 +222,18 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromGifCtx(gdIOCtxPtr fd) return 0; } im->interlace = BitSet(buf[8], INTERLACE); - if (! useGlobalColormap) { + if (!useGlobalColormap) { if (ReadColorMap(fd, bitPixel, localColorMap)) { - return 0; + gdImageDestroy(im); + return 0; } ReadImage(im, fd, width, height, localColorMap, BitSet(buf[8], INTERLACE), &ZeroDataBlock); } else { + if (!haveGlobalColormap) { + gdImageDestroy(im); + return 0; + } ReadImage(im, fd, width, height, ColorMap, BitSet(buf[8], INTERLACE), &ZeroDataBlock); @@ -293,8 +300,7 @@ DoExtension(gdIOCtx *fd, int label, int *Transparent, int *ZeroDataBlockP) if ((buf[0] & 0x1) != 0) *Transparent = buf[3]; - while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) != 0 && --maxcount >= 0) - ; + while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) != 0 && --maxcount >= 0); return FALSE; default: break;