diff --git a/src/blob.rs b/src/blob.rs index 0c0cf3072..c3d34d406 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -367,11 +367,12 @@ impl<'a> BlobObject<'a> { || img.get_pixel(x_max, y_max).0[3] == 0) { *vt = Viewtype::Image; + } else { + // Core doesn't auto-assign `Viewtype::Sticker` to messages and stickers coming + // from UIs shouldn't contain sensitive Exif info. + return Ok(name); } } - if *vt == Viewtype::Sticker && exif.is_none() { - return Ok(name); - } img = match orientation { Some(90) => img.rotate90(), diff --git a/src/blob/blob_tests.rs b/src/blob/blob_tests.rs index d4170bcc2..68472f867 100644 --- a/src/blob/blob_tests.rs +++ b/src/blob/blob_tests.rs @@ -416,6 +416,28 @@ async fn test_recode_image_balanced_png() { .unwrap(); } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_sticker_with_exif() { + let bytes = include_bytes!("../../test-data/image/logo.png"); + SendImageCheckMediaquality { + viewtype: Viewtype::Sticker, + bytes, + extension: "png", + // TODO: Pretend there's no Exif. Currently `exif` crate doesn't detect Exif in this image, + // so the test doesn't check all the logic it should. + has_exif: false, + original_width: 135, + original_height: 135, + res_viewtype: Some(Viewtype::Sticker), + compressed_width: 135, + compressed_height: 135, + ..Default::default() + } + .test() + .await + .unwrap(); +} + /// Tests that RGBA PNG can be recoded into JPEG /// by dropping alpha channel. #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -485,6 +507,7 @@ struct SendImageCheckMediaquality<'a> { pub(crate) original_width: u32, pub(crate) original_height: u32, pub(crate) orientation: i32, + pub(crate) res_viewtype: Option, pub(crate) compressed_width: u32, pub(crate) compressed_height: u32, pub(crate) set_draft: bool, @@ -500,6 +523,7 @@ impl SendImageCheckMediaquality<'_> { let original_width = self.original_width; let original_height = self.original_height; let orientation = self.orientation; + let res_viewtype = self.res_viewtype.unwrap_or(Viewtype::Image); let compressed_width = self.compressed_width; let compressed_height = self.compressed_height; let set_draft = self.set_draft; @@ -550,7 +574,7 @@ impl SendImageCheckMediaquality<'_> { } let bob_msg = bob.recv_msg(&sent).await; - assert_eq!(bob_msg.get_viewtype(), Viewtype::Image); + assert_eq!(bob_msg.get_viewtype(), res_viewtype); assert_eq!(bob_msg.get_width() as u32, compressed_width); assert_eq!(bob_msg.get_height() as u32, compressed_height); let file_saved = bob @@ -564,7 +588,7 @@ impl SendImageCheckMediaquality<'_> { } let (_, exif) = image_metadata(&std::fs::File::open(&file_saved)?)?; - assert!(exif.is_none()); + assert!(res_viewtype != Viewtype::Image || exif.is_none()); let img = check_image_size(file_saved, compressed_width, compressed_height); diff --git a/test-data/image/logo-exif.png b/test-data/image/logo-exif.png new file mode 100644 index 000000000..2942931f0 Binary files /dev/null and b/test-data/image/logo-exif.png differ