From 24dfe07c9b8ddfbdd03c633de99d03610f9e8071 Mon Sep 17 00:00:00 2001 From: Joe Drew Date: Wed, 3 Aug 2011 15:19:19 -0400 Subject: [PATCH] Bug 609499 - Some invalid GIF files don't terminate their LZW data with a 0-length block. Handle them better by handling them less specially. r=jrmuizel --- modules/libpr0n/decoders/nsGIFDecoder2.cpp | 25 ++++++---------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/modules/libpr0n/decoders/nsGIFDecoder2.cpp b/modules/libpr0n/decoders/nsGIFDecoder2.cpp index 522a9a65cf2a..460f0767f8e8 100644 --- a/modules/libpr0n/decoders/nsGIFDecoder2.cpp +++ b/modules/libpr0n/decoders/nsGIFDecoder2.cpp @@ -1027,27 +1027,14 @@ nsGIFDecoder2::WriteInternal(const char *aBuffer, PRUint32 aCount) case gif_sub_block: mGIFStruct.count = *q; - if (mGIFStruct.count) { - /* Still working on the same image: Process next LZW data block */ - /* Make sure there are still rows left. If the GIF data */ - /* is corrupt, we may not get an explicit terminator. */ - if (!mGIFStruct.rows_remaining) { -#ifdef DONT_TOLERATE_BROKEN_GIFS - mGIFStruct.state = gif_error; - break; -#else - /* This is an illegal GIF, but we remain tolerant. */ - GETN(1, gif_sub_block); -#endif - if (mGIFStruct.count == GIF_TRAILER) { - /* Found a terminator anyway, so consider the image done */ - GETN(1, gif_done); - break; - } - } + // We can have multiple LZW data blocks. Process the next, but only if + // there are any rows left. (If the GIF is invalid, we might not get an + // explicit 0-size block terminator.) + if (mGIFStruct.count && mGIFStruct.rows_remaining) { GETN(mGIFStruct.count, gif_lzw); } else { - /* See if there are any more images in this sequence. */ + // We've finished decoding this image. See if there are any more images + // in this sequence. EndImageFrame(); GETN(1, gif_image_start); }