Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
image/gif: "not enough image data" on gif that works in browser #38958
There are images which browsers can render but which image/gif chokes on.
The following runs successfully for most gifs:
But when trying to run it on a particular gif (below), this happens:
$ go run main.go
While my browser does indeed display it, that image is definitely corrupted and/or badly formed; imagemagick says:
and my system's image viewer also refuses to open it.
This is similar to #9856, when
To read this image, there need to be two changes to the gif decoder. I have made these changes in a modified
(1) Allow the lzw reader to encounter short reads in the stream.
(2) Handle zero-bytes sandwiched inside parts of the image.
After this, the author's test program correctly decodes the image.
The above image is even-more problematic. It contains a byte interpreted as an invalid LZW code (0x66) instead of (0x00) like the first image. To fix that, I had to elide almost all error checks and then ignore the 0x66 byte.
Perhaps other decoders silently ignore garbage input entirely and march forward hoping to eventually draw a valid-looking image. Which encoder produced these?
The image contains this metadata (which may give us a clue above the question above):