Skip to content

Commit 68d742b

Browse files
committed
fix(exif): hangs caused by fuzz testing.
1 parent a6d86b6 commit 68d742b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/exif/exif_iter.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{fmt::Debug, sync::Arc};
1+
use std::{collections::HashSet, fmt::Debug, sync::Arc};
22

33
use nom::{number::complete, sequence::tuple};
44
use thiserror::Error;
@@ -81,6 +81,7 @@ pub struct ExifIter {
8181

8282
// Iterating status
8383
ifds: Vec<IfdIter>,
84+
visited_offsets: HashSet<usize>,
8485
}
8586

8687
impl Debug for ExifIter {
@@ -115,6 +116,7 @@ impl ExifIter {
115116
tz,
116117
ifd0,
117118
ifds,
119+
visited_offsets: HashSet::new(),
118120
}
119121
}
120122

@@ -131,6 +133,7 @@ impl ExifIter {
131133
tz: self.tz.clone(),
132134
ifd0,
133135
ifds,
136+
visited_offsets: HashSet::new(),
134137
}
135138
}
136139

@@ -386,6 +389,15 @@ impl Iterator for ExifIter {
386389
// );
387390
// continue;
388391
// }
392+
393+
if new_ifd.offset > 0 {
394+
if self.visited_offsets.contains(&new_ifd.offset) {
395+
// Ignore repeated ifd parsing to avoid dead looping
396+
continue;
397+
}
398+
self.visited_offsets.insert(new_ifd.offset);
399+
}
400+
389401
let is_subifd = if new_ifd.ifd_idx == ifd.ifd_idx {
390402
// Push the current ifd before enter sub-ifd.
391403
self.ifds.push(ifd);

0 commit comments

Comments
 (0)