diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-03-29 02:59:09 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-03-29 02:59:09 +0000 |
commit | dde5e8f2c60bbc5da47ac90f6b48a41edd052ba3 (patch) | |
tree | 553ea00e7e7c789db15d3784293f72fa92a33dd2 | |
parent | d8fe5f2ef6eb392243d7a828de2c44784bfb8b55 (diff) | |
download | netpbm-mirror-dde5e8f2c60bbc5da47ac90f6b48a41edd052ba3.tar.gz netpbm-mirror-dde5e8f2c60bbc5da47ac90f6b48a41edd052ba3.tar.xz netpbm-mirror-dde5e8f2c60bbc5da47ac90f6b48a41edd052ba3.zip |
Fix handling of corrupted GIF with neither local nor global color map
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2434 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r-- | converter/other/giftopnm.c | 26 | ||||
-rw-r--r-- | doc/HISTORY | 3 |
2 files changed, 23 insertions, 6 deletions
diff --git a/converter/other/giftopnm.c b/converter/other/giftopnm.c index 1a42ffca..2e6ae1d9 100644 --- a/converter/other/giftopnm.c +++ b/converter/other/giftopnm.c @@ -239,7 +239,15 @@ typedef struct { struct GifScreen { unsigned int width; unsigned int height; + bool hasGlobalColorMap; + /* The stream has a global color map, to wit 'colorMap'. + (If the stream doesn't have a global color map, the individual + images must each have a local color map) + */ GifColorMap colorMap; + /* The global color map for the stream. Meaningful only if + 'hasGlobalColorMap' is true. + */ unsigned int colorResolution; unsigned int background; unsigned int aspectRatio; @@ -1744,24 +1752,26 @@ readGifHeader(FILE * const gifFileP, gifScreenP->aspectRatio = buf[6]; if (verbose) { - pm_message("GIF Width = %d GIF Height = %d " - "Pixel aspect ratio = %d (%f:1)", + pm_message("GIF Width = %u GIF Height = %u " + "Pixel aspect ratio = %u (%f:1)", gifScreenP->width, gifScreenP->height, gifScreenP->aspectRatio, gifScreenP->aspectRatio == 0 ? 1 : (gifScreenP->aspectRatio + 15) / 64.0); - pm_message("Colors = %d Color Resolution = %d", + pm_message("Global color count = %u Color Resolution = %u", cmapSize, gifScreenP->colorResolution); } if (buf[4] & GLOBALCOLORMAP) { + gifScreenP->hasGlobalColorMap = true; readColorMap(gifFileP, cmapSize, &gifScreenP->colorMap, &gifScreenP->hasGray, &gifScreenP->hasColor); if (verbose) { - pm_message("Color map %s grays, %s colors", + pm_message("Global color map %s grays, %s colors", gifScreenP->hasGray ? "contains" : "doesn't contain", gifScreenP->hasColor ? "contains" : "doesn't contain"); } - } + } else + gifScreenP->hasGlobalColorMap = false; if (gifScreenP->aspectRatio != 0 && gifScreenP->aspectRatio != 49) warnUserNotSquare(gifScreenP->aspectRatio); @@ -1972,10 +1982,14 @@ convertImage(FILE * const ifP, readColorMap(ifP, imageHeader.localColorMapSize, &localColorMap, &hasGray, &hasColor); currentColorMapP = &localColorMap; - } else { + } else if (gifScreen.hasGlobalColorMap) { currentColorMapP = &gifScreen.colorMap; hasGray = gifScreen.hasGray; hasColor = gifScreen.hasColor; + } else { + pm_error("Invalid GIF: " + "Image has no local color map and stream has no global " + "color map either."); } if (!skipIt) { diff --git a/doc/HISTORY b/doc/HISTORY index c55aee65..c310bf02 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -21,6 +21,9 @@ not yet BJH Release 10.70.00 pgmmorphconv: add -gradient. Thanks Michael Haardt <michael@moria.de>. + giftopnm: Fix bug: crashes if purported GIF has neither a global + color map nor a local one. + pgmmorphconv: fix bug: always produces PGM Plain format. pamtilt: fix bug: unconditional crash. Broken in Netpbm 10.63 |