From 02fc32cecf2effea2c0e311ccb5a9bb2a77008b3 Mon Sep 17 00:00:00 2001 From: Min Deng Date: Mon, 18 Nov 2024 09:09:28 +0800 Subject: [PATCH] fix(exif): #20 Panic depth shouldn't be greater than 1 --- src/exif/exif_iter.rs | 2 +- src/exif/travel.rs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/exif/exif_iter.rs b/src/exif/exif_iter.rs index bf6d968..ff0bdb0 100644 --- a/src/exif/exif_iter.rs +++ b/src/exif/exif_iter.rs @@ -379,7 +379,7 @@ impl Iterator for ExifIter { match entry { IfdEntry::IfdNew(new_ifd) => { if new_ifd.offset <= ifd.offset { - tracing::debug!( + tracing::error!( ?tag_code, ?new_ifd, "bad new SUB-IFD: offset is smaller than current IFD" diff --git a/src/exif/travel.rs b/src/exif/travel.rs index 70278b4..ee47000 100644 --- a/src/exif/travel.rs +++ b/src/exif/travel.rs @@ -141,11 +141,9 @@ impl<'a> IfdHeaderTravel<'a> { #[tracing::instrument(skip(self))] pub fn travel_ifd(&mut self, depth: usize) -> Result<(), ParsingError> { - // Currently, we ignore ifd1 data in *.tif files - if depth > 1 { - let msg = "depth shouldn't be greater than 1"; + if depth >= 3 { + let msg = "depth shouldn't be greater than 3"; tracing::error!(msg); - debug_assert!(false, "{}", msg); return Err(ParsingError::Failed(msg.into())); } @@ -161,7 +159,15 @@ impl<'a> IfdHeaderTravel<'a> { pos += IFD_ENTRY_SIZE; if let Some(ifd) = sub_ifd { - sub_ifds.push(ifd); + if ifd.offset <= self.offset { + tracing::error!( + current_ifd_offset = self.offset, + subifd_offset = ifd.offset, + "bad new SUB-IFD in TIFF: offset is smaller than current IFD" + ); + } else { + sub_ifds.push(ifd); + } } } @@ -169,7 +175,7 @@ impl<'a> IfdHeaderTravel<'a> { ifd.travel_ifd(depth + 1)?; } - // ignore ifd1 in TIFF + // Currently, we ignore ifd1 data in *.tif files Ok(()) } }