Skip to content

Corrupted JPEG does not result in visible error code #169

@dave-andersen

Description

@dave-andersen

This image is corrupt and will not decode in most image decoders (convert; opencv imread), but does not produce a decoding error in jpeg-decoder. Whether this is a problem is debatable, of course - for an image viewer it's good to be able to display the partial, corrupted image - but it's also nice for a library to be able to report that there's a glitch.

839442a6aa3dcca42f4962e8ec87b999

A simple program to validate the lack of error:

use anyhow::{anyhow, Result};

fn doit() -> Result<()> {
    let f = "839442a6aa3dcca42f4962e8ec87b999.jpg";
    let of = std::fs::File::open(f)?;
    let mut decoder = jpeg_decoder::Decoder::new(std::io::BufReader::new(of));
    decoder.read_info()?;
    let md = decoder.info().unwrap();
    println!("Metadata: {:#?} h/w: {} {}", md, md.height, md.width);
    let pixels = decoder.decode()?;
    println!("Pixel count: {}", pixels.len());
    println!("Happy image by jpeg crate");
    Ok(())
}
fn main() {
    if let Err(e) = doit() {
        println!("Error reading jpeg: {}", e);
    }
}

Which, when run, produces:

/target/debug/jpegcheck
Metadata: ImageInfo {
    width: 2560,
    height: 1920,
    pixel_format: RGB24,
} h/w: 1920 2560
Pixel count: 14745600
Happy image by jpeg crate

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions