-
Notifications
You must be signed in to change notification settings - Fork 18.1k
image/gif: decoding gif returns frame bounds larger than image bounds
error
#20856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Adding this because I saw a bunch of GIF-related issues pop up lately: I did a lot of GIF decoding with Go at some point as part of a scraper and image analysis tool. This was with 1.5, iirc. I checked some of the rejected files by hand and found that they are in fact invalid. Browsers seem to be much less strict about decoding them, and ffmpeg as well (as can be seen above). On one hand it'd be nice to have a less-strict mode, so we could actually parse most of the GIFs out there, on the other hand rejecting invalid files seems totally fine. |
However, non-standard gif is still a lot,i had to fine-tune its source code to be compatible with many non-standard files currently on the market
|
I’d love to know how many gifs out there cause an error with Relaxing the spec has security implications. So it’s a matter of determining how many gifs “in the wild” this affects and whether the relaxed rules can be done within a reasonable upper bound of complexity. |
@andybons I tested 10,000 random gifs and found 66 returned an error when decoding: https://gist.github.com/montanaflynn/88b5a69a107aa327ad16143561aff1c6 |
@montanaflynn awesome! Thanks for doing this. I'm also hoping to grab a larger corpus from within Google since we have a pretty large repository of things from the internet ;), but this is very helpful for initial investigation. Thanks again. |
Change https://golang.org/cl/119319 mentions this issue: |
LZW allows a meaningless 00 byte to occur at the end of the block. Close method is handling the case and comments detail the rational. This byte is not the clear code. When the byte occurs, the size of the image might be too large by 1 byte in any dimension. Calculations of image bounds are adapted in the proposed fix. If the byte has a value other than 00, an error will be returned as now. Existing tests required to adapt one error message. The list of all tests contains 20 cases. If you check the dimensions individually, the case occurs 11 times.
|
I don't think that (meaningless LZW bytes) is why the image/gif package is returning an error. I added a comment on https://golang.org/cl/119319 |
The frame and image bounds are checked when the image descriptor is read. The image data is read afterwards and the close of the data block discards that same byte. The check on the bounds must allow one byte outside the image bounds on only one of the dimension to take that case into account. After reading the data, it is needed to check that the bounds were correct. Instead of allowing the one byte difference every time, the new version of the fix checks the validity of the bounds afterwards. All images previously rejected are now accepted. The case submitted is now correctly rejected. |
The Tumblr GIF dataset might be useful for testing: https://github.com/raingo/TGIF-Release |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
Tried to decode this gif:
What did you expect to see?
The gif decoding not to return an error. The gif opens up in browsers, ffmpeg and photoshop.
When using ffmpeg you see this warning log:
What did you see instead?
I found this link which seems related:
https://groups.google.com/forum/#!topic/golang-codereviews/3zxEsAv4IuU
The text was updated successfully, but these errors were encountered: