-
Notifications
You must be signed in to change notification settings - Fork 18k
image/gif: decoding gif returns unknown block type: 0x01
error
#20804
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
unknown block type: 0x01
errorunknown block type: 0x01
error
I can repro at tip (0d33a89), ~Go 1.9beta2, and at Go 1.7, Go 1.6, Go 1.5, and Go 1.4. So not a regression. Targetting Go 1.10. |
Wassup @montanaflynn! |
The gif is probably invalid. With giflib 4.1.6 and the following program #include <stdio.h>
#include <gif_lib.h>
int main(int argc, char *argv[]){
GifFileType *m = DGifOpenFileName(argv[1]);
if (m == NULL) {
printf("DGifOpenFileName: error\n");
return -1;
}
int e = DGifSlurp(m);
if (e != GIF_OK) {
printf("DGifSlurp: error\n");
return -2;
}
return 0;
} I get |
I've examined the file. It is invalid. It's nearly a valid GIF but not quite. Why invalidThe decoder reads the file (including 34 At that point it looks for the next block to read and finds these last 2 bytes: It is not valid for a
What to doI'm not sure there's a great way to deal with this. Anything we do will mean making the decoder go outside the specification. However, here are some ideas:
The first idea seems like it might be tolerable. It means returning as much as we were able to decode (which in some cases may not be much useful at all), but still tell the caller something went wrong. Although this behaviour would probably be of limited usefulness. Callers would have to know that sometimes there could be useful data despite an error. I imagine this is why browsers and other decoders are able to show something. They may be returning whatever is valid. |
Sounds good @odeke-em. Thanks for the kind words! And for pinging me on this! |
Yeah, the short story is that it's an invalid GIF. The browser may be showing valid frames up until the bad block type, but there's still a bad block type. In general, the Go image codec APIs do not return partial results in case of error. Nor do they e.g. show the in-progress decodings of an interlaced PNG or progressive JPEG while decoding. There is no Go API to register a callback during png.Decode or jpeg.Decode. Any way to ask for partial results would probably have to be new API, due to Go 1.x compat, and would ideally be consistent across all of the various image packages, not just image/gif. Relatedly, it would be nice to have a consistent API for decoding moving images (both video like mp4 and animated GIFs), which might let the OP decode valid frames up until the bad block type, but again, that's an API design problem with larger scope than just patching image/gif. |
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 decode not to error
What did you see instead?
The text was updated successfully, but these errors were encountered: