Fix the mandrill.tiff regression (#145)
* fix mandrill.tiff regression from upstream * use contains_key(), added StripTileTagConflict error * updated test_div_zero, added test_no_rows_per_strip
This commit is contained in:
1 parent
458a713827
commit
e92cf219a9
4 files changed
+26
-21
No files matched your search
+17
-16
@@ -662,6 +662,8 @@ impl<R: Read + Seek> Decoder<R> {
|
|||||||
self.width = self.get_tag_u32(Tag::ImageWidth)?;
|
self.width = self.get_tag_u32(Tag::ImageWidth)?;
|
||||||
self.height = self.get_tag_u32(Tag::ImageLength)?;
|
self.height = self.get_tag_u32(Tag::ImageLength)?;
|
||||||
self.strip_decoder = None;
|
self.strip_decoder = None;
|
||||||
|
self.tile_decoder = None;
|
||||||
|
self.tile_attributes = None;
|
||||||
|
|
||||||
self.photometric_interpretation = self
|
self.photometric_interpretation = self
|
||||||
.find_tag_unsigned(Tag::PhotometricInterpretation)?
|
.find_tag_unsigned(Tag::PhotometricInterpretation)?
|
||||||
@@ -698,22 +700,21 @@ impl<R: Read + Seek> Decoder<R> {
|
|||||||
_ => return Err(TiffUnsupportedError::UnsupportedSampleDepth(self.samples).into()),
|
_ => return Err(TiffUnsupportedError::UnsupportedSampleDepth(self.samples).into()),
|
||||||
}
|
}
|
||||||
|
|
||||||
self.chunk_type =
|
let ifd = self.ifd.as_ref().unwrap();
|
||||||
match (
|
self.chunk_type = match (
|
||||||
self.get_tag_u32(Tag::RowsPerStrip),
|
ifd.contains_key(&Tag::StripByteCounts),
|
||||||
self.get_tag_u32(Tag::TileWidth),
|
ifd.contains_key(&Tag::StripOffsets),
|
||||||
self.get_tag_u32(Tag::TileLength),
|
ifd.contains_key(&Tag::TileByteCounts),
|
||||||
) {
|
ifd.contains_key(&Tag::TileOffsets),
|
||||||
(Ok(_), Err(_), Err(_)) => ChunkType::Strip,
|
) {
|
||||||
(Err(_), Ok(_), Ok(_)) => ChunkType::Tile,
|
(true, true, false, false) => ChunkType::Strip,
|
||||||
// TODO: The spec says not to use both strip-oriented fields and tile-oriented fields.
|
(false, false, true, true) => ChunkType::Tile,
|
||||||
// We can relax this later if it becomes a problem
|
(_, _, _, _) => {
|
||||||
_ => return Err(TiffError::FormatError(TiffFormatError::Format(
|
return Err(TiffError::FormatError(
|
||||||
String::from(
|
TiffFormatError::StripTileTagConflict,
|
||||||
"Neither strips nor tiles were found or both were used in the same file",
|
))
|
||||||
),
|
}
|
||||||
))),
|
};
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ pub enum TiffFormatError {
|
|||||||
SignedIntegerExpected(Value),
|
SignedIntegerExpected(Value),
|
||||||
Format(String),
|
Format(String),
|
||||||
RequiredTagEmpty(Tag),
|
RequiredTagEmpty(Tag),
|
||||||
|
StripTileTagConflict,
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
/// Do not match against this variant. It may get removed.
|
/// Do not match against this variant. It may get removed.
|
||||||
__NonExhaustive,
|
__NonExhaustive,
|
||||||
@@ -113,6 +114,7 @@ impl fmt::Display for TiffFormatError {
|
|||||||
}
|
}
|
||||||
Format(ref val) => write!(fmt, "Invalid format: {:?}.", val),
|
Format(ref val) => write!(fmt, "Invalid format: {:?}.", val),
|
||||||
RequiredTagEmpty(ref val) => write!(fmt, "Required tag {:?} was empty.", val),
|
RequiredTagEmpty(ref val) => write!(fmt, "Required tag {:?} was empty.", val),
|
||||||
|
StripTileTagConflict => write!(fmt, "File should contain either (StripByteCounts and StripOffsets) or (TileByteCounts and TileOffsets), other combination was found."),
|
||||||
__NonExhaustive => unreachable!(),
|
__NonExhaustive => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -287,7 +287,6 @@ fn test_tiled_incremental() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_div_zero() {
|
fn test_div_zero() {
|
||||||
use tiff::tags;
|
|
||||||
use tiff::{TiffError, TiffFormatError};
|
use tiff::{TiffError, TiffFormatError};
|
||||||
|
|
||||||
let image = [
|
let image = [
|
||||||
@@ -298,12 +297,10 @@ fn test_div_zero() {
|
|||||||
178, 178, 178,
|
178, 178, 178,
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut decoder = tiff::decoder::Decoder::new(std::io::Cursor::new(&image)).unwrap();
|
let err = tiff::decoder::Decoder::new(std::io::Cursor::new(&image)).unwrap_err();
|
||||||
|
|
||||||
let err = decoder.read_image().unwrap_err();
|
|
||||||
|
|
||||||
match err {
|
match err {
|
||||||
TiffError::FormatError(TiffFormatError::InvalidTagValueType(tags::Tag::TileWidth)) => {}
|
TiffError::FormatError(TiffFormatError::StripTileTagConflict) => {}
|
||||||
unexpected => panic!("Unexpected error {}", unexpected),
|
unexpected => panic!("Unexpected error {}", unexpected),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -385,3 +382,8 @@ fn test_stripped_image_overflow() {
|
|||||||
unexpected => panic!("Unexpected error {}", unexpected),
|
unexpected => panic!("Unexpected error {}", unexpected),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_no_rows_per_strip() {
|
||||||
|
test_image_sum_u8("no_rows_per_strip.tiff", ColorType::RGB(8), 99448840);
|
||||||
|
}
|
||||||
Binary file not shown.
Reference in new issue
Block a user