mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 15:26:30 +03:00
fix: Remove Exif with non-fatal errors from images
NB: This still doesn't help with detecting Exif in PNGs unfortunately.
This commit is contained in:
@@ -537,7 +537,11 @@ fn file_hash(src: &Path) -> Result<blake3::Hash> {
|
|||||||
fn image_metadata(file: &std::fs::File) -> Result<(u64, Option<exif::Exif>)> {
|
fn image_metadata(file: &std::fs::File) -> Result<(u64, Option<exif::Exif>)> {
|
||||||
let len = file.metadata()?.len();
|
let len = file.metadata()?.len();
|
||||||
let mut bufreader = std::io::BufReader::new(file);
|
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))
|
Ok((len, exif))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -334,6 +334,28 @@ async fn test_recode_image_2() {
|
|||||||
assert_correct_rotation(&img_rotated);
|
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)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_recode_image_balanced_png() {
|
async fn test_recode_image_balanced_png() {
|
||||||
let bytes = include_bytes!("../../test-data/image/screenshot.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)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_sticker_with_exif() {
|
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 {
|
SendImageCheckMediaquality {
|
||||||
viewtype: Viewtype::Sticker,
|
viewtype: Viewtype::Sticker,
|
||||||
bytes,
|
bytes,
|
||||||
|
|||||||
BIN
test-data/image/1000x1000-bad-exif.jpg
Normal file
BIN
test-data/image/1000x1000-bad-exif.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
Reference in New Issue
Block a user