From 6ea2f563e72f300b794a4367feb553ccb2f423f0 Mon Sep 17 00:00:00 2001 From: kubuntugamer Date: Thu, 8 Oct 2026 22:48:58 -0500 Subject: [PATCH] fix(io): a layered TIFF export warns that retained EXIF will be dropped (#1545) A TIFF export with --tiff-layers reported "EXIF not supported; it will be dropped" even though the file kept the tags. export_layered puts EXIF into the Photoshop image resources as 1058, which the TIFF writer emits as tag 34377 and the importer reads back, so reopening the file restored the original tags. ExportResult.warnings is documented as notes about what an export will lose, so the message was an incorrect loss report for an export that loses nothing. The TIFF codec has no EXIF directory, so the second copy handed to it in meta.exif was never written; it only existed to make the codec warn. That copy is gone, and with it the false warning. The flat-TIFF path still hands the codec the tags, still drops them, and still says so. The test is the issue's own claim checked in both directions: a layered export reports no EXIF loss AND the Artist tag survives the round trip, so the missing warning reflects a real absence of loss rather than a silenced one; a flat export is the control and keeps warning. It fails on the exact reported message before this change. Co-authored-by: Space Bunny Free --- crates/io/src/tiff_layers.rs | 5 ++++- crates/io/tests/tiff_layers.rs | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/crates/io/src/tiff_layers.rs b/crates/io/src/tiff_layers.rs index bb5770e5f67..598ffecd3e5 100644 --- a/crates/io/src/tiff_layers.rs +++ b/crates/io/src/tiff_layers.rs @@ -218,7 +218,10 @@ pub(crate) fn export_layered(doc: &Document, opts: &ExportOptions) -> Result Vec { + let mut artist = ARTIST.to_vec(); + artist.push(0); // ASCII NUL terminator + let mut v = b"II*\0\x08\0\0\0".to_vec(); // TIFF header, first IFD at 8 + v.extend_from_slice(&1u16.to_le_bytes()); // one entry + v.extend_from_slice(&0x013bu16.to_le_bytes()); // Artist + v.extend_from_slice(&2u16.to_le_bytes()); // ASCII + v.extend_from_slice(&(artist.len() as u32).to_le_bytes()); + v.extend_from_slice(&26u32.to_le_bytes()); // value offset: 8 + 2 + 12 + 4 + v.extend_from_slice(&0u32.to_le_bytes()); // no next IFD + v.extend_from_slice(&artist); + v +} + +/// #1545: a layered TIFF carries EXIF as Photoshop resource 1058 and reads it back, so it must +/// not report a loss it never makes. A flat TIFF really does lose the tags and still says so. +#[test] +fn layered_tiff_keeps_exif_without_claiming_a_loss() { + let mut d = gen_doc(ColorMode::Rgb, SampleType::U8, Features::PIXELS); + d.metadata.exif = Some(std::sync::Arc::new(exif())); + + let r = tiff(&d, true); + assert!(!r.warnings.iter().any(|w| w.contains("EXIF")), "a layered TIFF keeps EXIF, so it must not claim to drop it: {:?}", r.warnings); + // ...and the tags really are in the file, so the missing warning is a true absence of loss. + let back = import("x.tif", &r.bytes).unwrap().document; + let kept = back.metadata.exif.as_deref().expect("EXIF survives the layered export"); + assert!(kept.windows(ARTIST.len()).any(|w| w == ARTIST), "the Artist tag did not survive: {kept:?}"); + + // The control from the issue: the flat path drops it for real, and keeps reporting that. + let flat = tiff(&d, false); + assert!(flat.warnings.iter().any(|w| w.contains("EXIF")), "a flat TIFF really does lose EXIF: {:?}", flat.warnings); +} + #[test] fn discard_layers_writes_a_flat_file() { let d = gen_doc(ColorMode::Rgb, SampleType::U8, Features::PIXELS);