Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading a larger tiff with PackBits fails if original reader is a bufreader, but worked in 0.7.1 #194

Closed
ChrisRega opened this issue Dec 6, 2022 · 2 comments

Comments

@ChrisRega
Copy link

Hello!

History

We are using image-rs to load and validate tiff files produced by an internal software (C++ with libtiff for writing). Until 0.7.1 we could just read those without an issue. Since then and up to 0.8.0 we run into:
IoError(Error { kind: UnexpectedEof, message: "failed to fill whole buffer" }).

Our debugging

So we debugged into this, originally coming from the image crate and found that it wraps the reader into a bufreader before trying to decode the tiff.
So I added a unit-test to reproduce the issue inside image-tiff which looks like:

#[test]
fn vgsm_tiff_large_rgb_packbits_fails() {
    let path = PathBuf::from(TEST_IMAGE_DIR).join("screenshot.tif");
    let mut decoder =
        Decoder::new(BufReader::new(File::open(path).expect("Cannot find test image!"))).unwrap();

    let mut img_res = decoder.read_image().unwrap();
}

#[test]
fn vgsm_tiff_large_rgb_packbits_passes() {
    let path = PathBuf::from(TEST_IMAGE_DIR).join("screenshot.tif");
    let mut decoder =
        Decoder::new(File::open(path).expect("Cannot find test image!")).unwrap();

    let mut img_res = decoder.read_image().unwrap();
}

While trying to create a minimum example, I also stumbled across the fact, that the image has to be of significant size (35x20px did not fail, 1920x1280 fails). After some chunks (with the attached image its in chunk 6), the PackBitsReader tries to read the header with self.reader.read_exact(&mut header)?; (stream.rs line ~370) and fails out.
Chunk offsets look identical between the readers

File for reproduction

Tiff-file is attached gzipped:
screenshot.tif.gz

Snipped above should reproduce it as unit-test inside decode_images.rs

Any help is greatly appreciated :)
Many thanks in advance for your great work!

@ChrisRega ChrisRega changed the title Reading a larger tiff with PackBits fails if original reader is a bufreader Reading a larger tiff with PackBits fails if original reader is a bufreader, but worked in 0.7.1 Dec 6, 2022
@HeroicKatora
Copy link
Member

Can you check if #193 fixes it? If so then the working code is completely incidental and was probably previously only masked by some other details (such as a small image size).

@ChrisRega
Copy link
Author

Indeed, seems to pass on master! So we'll just patiently wait for a new release. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants