Skip to content

Commit

Permalink
fix(exif): #20 Panic depth shouldn't be greater than 1
Browse files Browse the repository at this point in the history
  • Loading branch information
mindeng committed Nov 18, 2024
1 parent 1c3bc2a commit 02fc32c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/exif/exif_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 12 additions & 6 deletions src/exif/travel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand All @@ -161,15 +159,23 @@ 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);
}
}
}

for mut ifd in sub_ifds {
ifd.travel_ifd(depth + 1)?;
}

// ignore ifd1 in TIFF
// Currently, we ignore ifd1 data in *.tif files
Ok(())
}
}
Expand Down

0 comments on commit 02fc32c

Please sign in to comment.