feat: detect image format from magic bytes, not file extension

- Fixes misnamed files (e.g. JPEG saved as .png) being skipped
- Uses image::ImageReader with guessed format from content
- Fixes Android screenshots with wrong extension being skipped
- New test: misnamed_jpeg_as_png_still_scanned
- 22 tests passing
This commit is contained in:
admin
2026-04-27 23:57:20 +00:00
parent deb5321a8a
commit 9dc8a495bb
2 changed files with 23 additions and 2 deletions

View File

@@ -133,3 +133,16 @@ fn cli_binary_reports_duplicates() {
assert!(stdout.contains("[exact]"), "output should contain exact groups: {stdout}");
assert!(stdout.contains("[similar]"), "output should contain similar groups: {stdout}");
}
#[test]
fn misnamed_jpeg_as_png_still_scanned() {
// fake_png.png is actually JPEG data with .png extension
let dir = Path::new("/a0/usr/projects/deduper/.a0proj/test_media/images");
let entries = scan_images(dir).expect("scan");
let fake = entries.iter().find(|e| e.path.ends_with("fake_png.png"));
assert!(fake.is_some(), "misnamed JPEG-as-PNG should be scanned via magic bytes");
// should have same hash as orig.jpg since it's a copy
let orig = entries.iter().find(|e| e.path.ends_with("orig.jpg")).unwrap();
let fake = fake.unwrap();
assert_eq!(orig.sha256, fake.sha256, "same content = same sha256");
}