image-rs / image

Encoding and decoding images in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebPDecoder.into_frames() always returns an error at the end of the file instead of ending iteration normally

awused opened this issue · comments

Broken in 0.25.x and git head, unsure about when it started since I was hoping to replace the webp-animation crate with this, but it's probably been unused and broken for a while.

Expected

Frames iterator returns None after the last frame.

Actual behaviour

Returns either a DecodingError { format: Exact(WebP), underlying: Some(NoMoreFrames) } or an IO Error from a BufReader as it tries to read past the end of the file.

Reproduction steps

Call into_frames on an WebPDecoder for an animated image. Here's a test that runs on your own test data.

#[test]
fn webp_decode() {
    let decoder = WebPDecoder::new(std::io::Cursor::new(
        std::fs::read("tests/images/webp/extended_images/anim.webp").unwrap(),
    ))
    .unwrap();
    let frames = decoder.into_frames();
    for result in frames {
        result.unwrap();
    }
}
thread 'webp_decode' panicked at tests/limits_anim.rs:20:16:
called `Result::unwrap()` on an `Err` value: Decoding(DecodingError { format: Exact(WebP), underlying: Some(NoMoreFrames) })

Probably happened in the switch to using image-webp. The fix should be to call num_frames at the start and then return None once that many frames have been decoded. Or maybe once num_frames * loop_count many frames have been decoded