Skip to content

Commit 966cd48

Browse files
committed
fix: Remove Exif with non-fatal errors from images
NB: This still doesn't help with detecting Exif in PNGs unfortunately.
1 parent 209a802 commit 966cd48

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/blob.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,11 @@ fn file_hash(src: &Path) -> Result<blake3::Hash> {
538538
fn image_metadata(file: &std::fs::File) -> Result<(u64, Option<exif::Exif>)> {
539539
let len = file.metadata()?.len();
540540
let mut bufreader = std::io::BufReader::new(file);
541-
let exif = exif::Reader::new().read_from_container(&mut bufreader).ok();
541+
let exif = exif::Reader::new()
542+
.continue_on_error(true)
543+
.read_from_container(&mut bufreader)
544+
.or_else(|e| e.distill_partial_result(|_errors| {}))
545+
.ok();
542546
Ok((len, exif))
543547
}
544548

src/blob/blob_tests.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ async fn test_selfavatar_copy_without_recode() {
258258

259259
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
260260
async fn test_recode_image_1() {
261+
// `exiftool` reports for this file "Bad offset for IFD0 XResolution", still Exif must be
262+
// detected and removed.
261263
let bytes = include_bytes!("../../test-data/image/avatar1000x1000.jpg");
262264
SendImageCheckMediaquality {
263265
viewtype: Viewtype::Image,
@@ -418,7 +420,7 @@ async fn test_recode_image_balanced_png() {
418420

419421
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
420422
async fn test_sticker_with_exif() {
421-
let bytes = include_bytes!("../../test-data/image/logo.png");
423+
let bytes = include_bytes!("../../test-data/image/logo-exif.png");
422424
SendImageCheckMediaquality {
423425
viewtype: Viewtype::Sticker,
424426
bytes,
0 Bytes
Loading

0 commit comments

Comments
 (0)