Remove tile processing and add error handling

I removed the code that checked the tile attributes. Because I would
rather later on PR something that works than a half-baked solution.
This commit is contained in:
ruffson committed 2020-09-26 14:07:27 +02:00
1 parent 35ea719d9e
commit cb900819d9
2 files changed
+14 -11

No files matched your search

+10 -11
View File
@@ -931,20 +931,19 @@ impl<R: Read + Seek> Decoder<R> {
} }
pub fn read_jpeg(&mut self) -> TiffResult<DecodingResult> { pub fn read_jpeg(&mut self) -> TiffResult<DecodingResult> {
let offsets: Vec<u32>; let offsets = self.get_tag_u32_vec(Tag::StripOffsets)?;
let bytes: Vec<u32>; let bytes = self.get_tag_u32_vec(Tag::StripByteCounts)?;
let jpeg_tables: Vec<u8> = self.get_tag_u8_vec(Tag::JPEGTables)?; let jpeg_tables: Vec<u8> = self.get_tag_u8_vec(Tag::JPEGTables)?;
match self.find_tag(Tag::TileOffsets) { if offsets.len() == 0 {
Ok(None) => { return Err(TiffError::FormatError(TiffFormatError::RequiredTagEmpty(
offsets = self.get_tag_u32_vec(Tag::StripOffsets)?; Tag::StripOffsets,
bytes = self.get_tag_u32_vec(Tag::StripByteCounts)?; )));
} }
Ok(_) => { if offsets.len() != bytes.len() {
offsets = self.get_tag_u32_vec(Tag::TileOffsets)?; return Err(TiffError::FormatError(TiffFormatError::Format(
bytes = self.get_tag_u32_vec(Tag::TileByteCounts)?; String::from("Size mismatch of StripOffsets and StripByteCounts"),
} )));
Err(e) => return Err(e),
} }
let mut res_img = Vec::with_capacity(offsets[0] as usize); let mut res_img = Vec::with_capacity(offsets[0] as usize);
+4
View File
@@ -50,6 +50,7 @@ pub enum TiffFormatError {
SignedIntegerExpected(Value), SignedIntegerExpected(Value),
InflateError(InflateError), InflateError(InflateError),
Format(String), Format(String),
RequiredTagEmpty(Tag),
#[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,
@@ -84,6 +85,9 @@ impl fmt::Display for TiffFormatError {
Format(ref val) => { Format(ref val) => {
write!(fmt, "Invalid format: {:?}.", val) write!(fmt, "Invalid format: {:?}.", val)
} }
RequiredTagEmpty(ref val) => {
write!(fmt, "Required tag {:?} was empty.", val)
}
__NonExhaustive => unreachable!(), __NonExhaustive => unreachable!(),
} }
} }