Skip to content
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

Fails to decode .gif #138

Open
lilith opened this issue Sep 29, 2022 · 5 comments
Open

Fails to decode .gif #138

lilith opened this issue Sep 29, 2022 · 5 comments

Comments

@lilith
Copy link

lilith commented Sep 29, 2022

In 0.11.4, I can't get this to decode: I get DecodingFormatError { underlying: "unexpected EOF" }
It works in Chrome/Win/Brave.
https://user-images.githubusercontent.com/657201/139770827-18e25c4e-eb0a-4058-ba48-ddc3849090ee.gif

@HeroicKatora
Copy link
Member

HeroicKatora commented Sep 29, 2022

This image is missing a Trailer block to end its data stream. The netbpm tools agree with this:

$ # /usr/bin/giftopnm is owned by netpbm 10.73.37-2
$ giftopnm /tmp/139770827-18e25c4e-eb0a-4058-ba48-ddc3849090ee.gif > /dev/null 
giftopnm: Error accessing Image 67 of stream.  File read error where start of image descriptor or end of GIF expected.  End of file encountered

Frames before this are handled fine but eagerly decoding the complete file will surface the error. Is there any other error strategy that we could do here instead to recover?

@mpwsh
Copy link

mpwsh commented Nov 29, 2022

Im having the same problem. Now gif won't decode anything, it fails with unexpected EOF.
Only thing i did was update from 0.11.4 to 0.12.0 and move to toolchain 1.65.0.

wget "https://ipfs.io/ipfs/bafybeihqwohkbcwf2egmwd4lnriaa63xc3eqfbyb4i4qftjikyp5wtwlqi/5220.gif" -O claydino.gif
giftopnm claydino.gif  > /dev/null

With gif lib (code available here )

[2022-11-29T16:34:13Z INFO  imgopt::utils] Opening file:: storage/base/ipfs/bafybeihqwohkbcwf2egmwd4lnriaa63xc3eqfbyb4i4qftjikyp5wtwlqi/5220.gif
[2022-11-29T16:34:13Z INFO  imgopt::utils] reading image from file: took 638 µs
[2022-11-29T16:34:13Z WARN  imgopt::img] starting read_info
[2022-11-29T16:34:13Z ERROR imgopt::img] unexpected EOF

Is there something we can do to handle the 'unexpected EOF' error?

@mpwsh
Copy link

mpwsh commented Nov 29, 2022

nvm, its working again, my fault, sorry.
I tried the basic check.rs example on the repo and the gif worked just fine, so it was 100% on me.

I think(?) this was causing the error.

    let mut file = fs::File::open(input_path)?;
    // I was moving the data into a vec before using read_info
    let mut data = Vec::new();
    file.read_to_end(&mut data)?;
   //// Moving the above after using read_info solved the issue
   
    let mut reader = {
        let mut options = gif::DecodeOptions::new();
        options.set_color_output(gif::ColorOutput::Indexed);
        options.allow_unknown_blocks(true);
        options.read_info(&file).unwrap()
    };

     
    /*  moved  here
     let mut data = Vec::new();
    file.read_to_end(&mut data)?;
   */

@fintelia
Copy link
Contributor

Yeah, read_to_end leaves the file descriptor pointing at the end of the file. If the decoder later tries to read even a single byte it'll get back an error that there's no more data to read

@lilith
Copy link
Author

lilith commented Feb 3, 2023

I call read_info() first. Is there a way to tolerate GIF files without a trailer block the way a browser will?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants