diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index a355327..4743b9a 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -811,15 +811,6 @@ impl Decoder { self.reader.byte_order } - fn read_ifd_offset_nonrepeating(&mut self) -> TiffResult { - let result = self.read_ifd_offset()?; - if self.seen_ifds.insert(result) { - Ok(result) - } else { - Err(TiffError::FormatError(TiffFormatError::CycleInOffsets)) - } - } - #[inline] pub fn read_ifd_offset(&mut self) -> Result { if self.bigtiff { @@ -978,9 +969,13 @@ impl Decoder { }; dir.insert(tag, entry); } - self.next_ifd = match self.read_ifd_offset_nonrepeating()? { - 0 => None, - n => Some(n), + + self.next_ifd = { + let result = self.read_ifd_offset()?; + if !self.seen_ifds.insert(result) { + return Err(TiffError::FormatError(TiffFormatError::CycleInOffsets)); + } + Some(result) }; Ok(dir) }