etemesi254 / zune-image

A fast and memory efficient image library in Rust
Other
308 stars 30 forks source link

Panic on decoding jpg #176

Closed Jelenkee closed 4 months ago

Jelenkee commented 5 months ago

Rust: 1.77.0 zune_jpeg: 0.4.11 image: 0.25.0

Hi, since the image crate switched to zune-jpeg, I get an error when decoding a specific image.

Error:

thread 'main' panicked at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zune-jpeg-0.4.11/src/worker.rs:411:13:
assertion `left == right` failed
  left: 6912
 right: 3456
stack backtrace:
   0: rust_begin_unwind
             at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/std/src/panicking.rs:647:5
   1: core::panicking::panic_fmt
             at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/panicking.rs:72:14
   2: core::panicking::assert_failed_inner
             at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/panicking.rs:342:17
   3: core::panicking::assert_failed
             at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/panicking.rs:297:5
   4: zune_jpeg::worker::upsample
             at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zune-jpeg-0.4.11/src/worker.rs:411:13
   5: zune_jpeg::mcu::<impl zune_jpeg::decoder::JpegDecoder<T>>::post_process
             at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zune-jpeg-0.4.11/src/mcu.rs:385:17
   6: zune_jpeg::mcu_prog::<impl zune_jpeg::decoder::JpegDecoder<T>>::finish_progressive_decoding
             at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zune-jpeg-0.4.11/src/mcu_prog.rs:551:13
   7: zune_jpeg::mcu_prog::<impl zune_jpeg::decoder::JpegDecoder<T>>::decode_mcu_ycbcr_progressive
             at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zune-jpeg-0.4.11/src/mcu_prog.rs:198:9
   8: zune_jpeg::decoder::JpegDecoder<T>::decode_into
             at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zune-jpeg-0.4.11/src/decoder.rs:706:13
   9: <image::codecs::jpeg::decoder::JpegDecoder<R> as image::image::ImageDecoder>::read_image
             at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/image-0.25.0/src/codecs/jpeg/decoder.rs:84:9
  10: <image::codecs::jpeg::decoder::JpegDecoder<R> as image::image::ImageDecoder>::read_image_boxed
             at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/image-0.25.0/src/codecs/jpeg/decoder.rs:97:9
  11: <alloc::boxed::Box<T> as image::image::ImageDecoder>::read_image
             at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/image-0.25.0/src/image.rs:715:9
  12: image::image::decoder_to_vec
             at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/image-0.25.0/src/image.rs:602:5
  13: image::dynimage::decoder_to_image
             at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/image-0.25.0/src/dynimage.rs:1018:23
  14: image::dynimage::DynamicImage::from_decoder
             at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/image-0.25.0/src/dynimage.rs:188:9
  15: image::io::reader::Reader<R>::decode
             at /home/gaus/.cargo/registry/src/index.crates.io-6f17d22bba15001f/image-0.25.0/src/io/reader.rs:271:9
  16: weide::img::read_image
             at ./src/img.rs:109:19
  17: weide::run
             at ./src/main.rs:40:15
  18: weide::main
             at ./src/main.rs:25:23
  19: core::ops::function::FnOnce::call_once
             at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/ops/function.rs:250:5

Code:

        let file = File::open(&path).with_context(|| format!("File {} not found", &path))?;
        let buf_read = BufReader::new(file);
        let img = Reader::new(buf_read)
            .with_guessed_format()?
            .decode()
            .context("input file is not an image")?;

the image broken

I guess the image is somehow broken, but every image viewer/browser can display it without problems.

FYI @fintelia

etemesi254 commented 5 months ago

it's not broken, it can be decoded, i moved it to an error in a new version but it seems it just doesn't appear on fuzz generated images and I should probably fix it, doing so in a few

RedPixlFox commented 5 months ago

I guess it happens here