image-rs / image-tiff

TIFF decoding and encoding library in pure Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decoder regression: mandrill.tiff from upstream

RReverser opened this issue · comments

I've tried to upgrade upstream image crate to tiff 0.7.0, and it uncovered a regression bug: upstream image mandrill.tiff used to decode with 0.6.0, but fails with 0.7.0 with:

Cannot create decoder: FormatError(Format("Neither strips nor tiles were found or both were used in the same file"))

I verified that this problem is reproducible with just image-tiff too, so it's not an issue with integration in the image crate itself. It's also an uncompressed TIFF, so doesn't seem related to my deflate PR (#132) either.

Beyond that, I'm not that familiar with changes between releases, so leaving it up to others to debug this further.

Sorry, this is the result of some code I added.

self.chunk_type =
match (
self.get_tag_u32(Tag::RowsPerStrip),
self.get_tag_u32(Tag::TileWidth),
self.get_tag_u32(Tag::TileLength),
) {
(Ok(_), Err(_), Err(_)) => ChunkType::Strip,
(Err(_), Ok(_), Ok(_)) => ChunkType::Tile,
// TODO: The spec says not to use both strip-oriented fields and tile-oriented fields.
// We can relax this later if it becomes a problem
_ => return Err(TiffError::FormatError(TiffFormatError::Format(
String::from(
"Neither strips nor tiles were found or both were used in the same file",
),
))),
};

This file has StripOffsets and StripByteCounts, but doesn't have RowsPerStrip, which I didn't expect.
Maybe I should just check for (StripOffsets && StripByteCounts) || (TileOffsets && TileByteCounts), otherwise reject the file ?