diff --git a/src/blob.rs b/src/blob.rs index 1c1630d2d..ca47c65a4 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -537,7 +537,11 @@ fn file_hash(src: &Path) -> Result { fn image_metadata(file: &std::fs::File) -> Result<(u64, Option)> { let len = file.metadata()?.len(); let mut bufreader = std::io::BufReader::new(file); - let exif = exif::Reader::new().read_from_container(&mut bufreader).ok(); + let exif = exif::Reader::new() + .continue_on_error(true) + .read_from_container(&mut bufreader) + .or_else(|e| e.distill_partial_result(|_errors| {})) + .ok(); Ok((len, exif)) } diff --git a/src/blob/blob_tests.rs b/src/blob/blob_tests.rs index 68472f867..a63c08602 100644 --- a/src/blob/blob_tests.rs +++ b/src/blob/blob_tests.rs @@ -334,6 +334,28 @@ async fn test_recode_image_2() { assert_correct_rotation(&img_rotated); } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_recode_image_bad_exif() { + // `exiftool` reports for this file "Bad offset for IFD0 XResolution", still Exif must be + // detected and removed. + let bytes = include_bytes!("../../test-data/image/1000x1000-bad-exif.jpg"); + SendImageCheckMediaquality { + viewtype: Viewtype::Image, + media_quality_config: "0", + bytes, + extension: "jpg", + has_exif: true, + original_width: 1000, + original_height: 1000, + compressed_width: 1000, + compressed_height: 1000, + ..Default::default() + } + .test() + .await + .unwrap(); +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_recode_image_balanced_png() { let bytes = include_bytes!("../../test-data/image/screenshot.png"); @@ -418,7 +440,7 @@ async fn test_recode_image_balanced_png() { #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_sticker_with_exif() { - let bytes = include_bytes!("../../test-data/image/logo.png"); + let bytes = include_bytes!("../../test-data/image/logo-exif.png"); SendImageCheckMediaquality { viewtype: Viewtype::Sticker, bytes, diff --git a/test-data/image/1000x1000-bad-exif.jpg b/test-data/image/1000x1000-bad-exif.jpg new file mode 100644 index 000000000..e39d6bf40 Binary files /dev/null and b/test-data/image/1000x1000-bad-exif.jpg differ