Skip to content

Unexpected change of behavior when reading partial data #639

@anforowicz

Description

@anforowicz

A Skia test decodes the first 0x8D bytes of a PNG image and expects the first 10 rows of the images to successfully decode before getting UnexpectedEof error. This roughly translates to the following ad-hoc test in the png crate:

#[test]
fn test_partial_decode() {
    // The first 0x8D bytes from the following test image from Skia:
    // resources/images/apng-test-suite--dispose-ops--none-basic.png
    let partial_png: &[u8] = &[
        0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48,
        0x44, 0x52, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x40, 0x08, 0x06, 0x00, 0x00,
        0x00, 0xd2, 0xd6, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x08, 0x61, 0x63, 0x54, 0x4c, 0x00,
        0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0xb9, 0xea, 0x8a, 0x56, 0x00, 0x00, 0x00,
        0x1a, 0x66, 0x63, 0x54, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
        0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00,
        0x64, 0x00, 0x01, 0x26, 0x12, 0x2f, 0xe0, 0x00, 0x00, 0x00, 0x93, 0x49, 0x44, 0x41,
        0x54, 0x78, 0x9c, 0xed, 0xd2, 0xa1, 0x01, 0x00, 0x30, 0x10, 0x84, 0xb0, 0xdb, 0x7f,
        0xe9, 0xef, 0x18, 0x15, 0x44, 0xc4, 0x23, 0xd8, 0x6d, 0x47, 0xd7, 0x7e, 0x07, 0x60,
        0x00, 0x0c, 0x80, 0x01, 0x30, 0x00, 0x06, 0xc0, 0x00, 0x18, 0x00, 0x03, 0x60, 0x00,
        0x0c,
    ];

    let mut reader = Decoder::new(std::io::Cursor::new(partial_png)).read_info().unwrap();
    let mut row = vec![0; reader.output_buffer_size()];
    for i in 0..10 {
        dbg!(i);
        let result = reader.read_row(&mut row);
        assert!(result.is_ok());
    }
    let result = reader.read_row(&mut row);
    let DecodingError::IoError(err) = result.unwrap_err()
        else { panic!("Unexpected error variant"); };
    assert_eq!(err.kind(), std::io::ErrorKind::UnexpectedEof);
}

The tests above (the Skia test and the ad-hoc unit test) have been passing in 0.18-rc, but are failing in 0.18. The failure is that the very first call to read_row returns UnexpectedEof. FWIW git bisect blames the change of behavior on 303b3e4. I'll try to dig in more later today or tomorrow.

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