Skip to content

Commit

Permalink
test: add test case for detecting endless loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mindeng committed Oct 23, 2024
1 parent 4f7c139 commit d232525
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/exif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ pub async fn parse_exif_async<T: AsyncRead + Unpin + Send>(
#[cfg(test)]
#[allow(deprecated)]
mod tests {
use std::{sync::mpsc, thread, time::Duration};

use crate::{
file::MimeImage,
testkit::{open_sample, read_sample},
Expand Down Expand Up @@ -349,4 +351,21 @@ mod tests {
.collect();
assert_eq!(res.join(", "), "Make => Apple, Model => iPhone 12 Pro");
}

#[test]
fn endless_loop() {
let (sender, receiver) = mpsc::channel();

thread::spawn(move || {
let name = "endless_loop.jpg";
let f = open_sample(name).unwrap();
let iter = parse_exif(f, None).unwrap().unwrap();
let _: Exif = iter.into();
sender.send(()).unwrap();
});

receiver
.recv_timeout(Duration::from_secs(1))
.expect("There is an infinite loop in the parsing process!");
}
}
Binary file added testdata/endless_loop.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d232525

Please sign in to comment.