Skip to content

Panic when decoding JPEG: range end index out of range for slice #314

@Yomihay-qut

Description

@Yomihay-qut

Description
Hello, I discovered a panic in zune-jpeg (version 0.5.5) while fuzzing image-tiff with cargo-fuzz. The parser panics with an index out of bounds error in src/mcu.rs.

The issue seems to occur during the post-processing of MCU blocks, where a slice access uses an index that exceeds the slice length.

Panic Location
src/mcu.rs:596:44

Reproduction Code
Here is a minimal reproduction case that triggers the crash (using cargo fuzz):

  1. Clone the repository.
  2. Run the fuzzer with the provided crash artifact.
cargo fuzz run decode_image fuzz/artifacts/decode_image/crash-916ae517a53265acbdfae0bbb2df69bfe46e3cf6

Stack Trace

thread '<unnamed>' panicked at /home/zx/.cargo/registry/src/rsproxy.cn-e3de039b2554c837/zune-jpeg-0.5.5/src/mcu.rs:596:44:
range end index 5248 out of range for slice of length 5120
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::slice::index::slice_index_fail::do_panic::runtime
   3: core::slice::index::slice_index_fail
   4: core::slice::index::index
   5: core::slice::index::index
   6: <zune_jpeg::decoder::JpegDecoder<zune_core::bytestream::reader::no_std_readers::ZCursor<alloc::vec::Vec<u8>>>>::post_process::{closure#1}
             at /home/zx/.cargo/registry/src/rsproxy.cn-e3de039b2554c837/zune-jpeg-0.5.5/src/mcu.rs:596:44
   7: <zune_jpeg::decoder::JpegDecoder<zune_core::bytestream::reader::no_std_readers::ZCursor<alloc::vec::Vec<u8>>>>::post_process
             at /home/zx/.cargo/registry/src/rsproxy.cn-e3de039b2554c837/zune-jpeg-0.5.5/src/mcu.rs:699:13
   8: <zune_jpeg::decoder::JpegDecoder<zune_core::bytestream::reader::no_std_readers::ZCursor<alloc::vec::Vec<u8>>>>::decode_mcu_ycbcr_baseline
             at /home/zx/.cargo/registry/src/rsproxy.cn-e3de039b2554c837/zune-jpeg-0.5.5/src/mcu.rs:254:26
   9: <zune_jpeg::decoder::JpegDecoder<zune_core::bytestream::reader::no_std_readers::ZCursor<alloc::vec::Vec<u8>>>>::decode
             at /home/zx/.cargo/registry/src/rsproxy.cn-e3de039b2554c837/zune-jpeg-0.5.5/src/decoder.rs:208:14

Environment

  • zune-jpeg version: 0.5.5
  • Rust: stable (used via cargo-fuzz)
  • OS: Linux

Multiple samples

  • Multiple fuzzing artifacts in Panic_IndexOOB__zune-jpeg-0.5.5_src_mcu.rs_596.zip reproduce this crash; include one of these artifacts when testing.

Panic_IndexOOB__zune-jpeg-0.5.5_src_mcu.rs_596.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions