LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
LR-EXP-METADATA: reject Originals with unreadable XMP
ronibalthazar77471ca376d9
diff --git a/crates/engine/src/export.rs b/crates/engine/src/export.rsindex 53279ccc5..4c593beab 100644--- a/crates/engine/src/export.rs+++ b/crates/engine/src/export.rs@@ -1837,6 +1837,14 @@ impl PreparedExport {if remove_location {let metadata = lightcraft_meta::try_extract(&bytes).map_err(|e| format!("{label}: can't verify location metadata in this original file: {e}"))?;+ if !bytes.starts_with(b"8BPS") {+ let embedded = lightcraft_meta::embedded(&bytes);+ if let Some(xmp) = embedded.xmp.as_deref() {+ lightcraft_meta::parse_xmp(xmp).map_err(|e| {+ format!("{label}: can't verify location metadata in this original file: malformed embedded XMP: {e}")+ })?;+ }+ }let embeds_place_name =[metadata.sublocation.as_deref(), metadata.city.as_deref(), metadata.state.as_deref(), metadata.country.as_deref()].into_iter()@@ -1844,7 +1852,7 @@ impl PreparedExport {.any(|value| !value.trim().is_empty());if metadata.gps.is_some() || embeds_place_name {return Err(format!(- "{label}: can't remove the location from an original file that embeds GPS or place names; export as JPEG, TIFF or DNG instead"+ "{label}: can't remove the location from an original file that embeds GPS or place names; export as JPEG or TIFF, or as DNG for a raw photo"));}}diff --git a/crates/engine/src/tests_export.rs b/crates/engine/src/tests_export.rsindex 1df6702a8..c0377409f 100644--- a/crates/engine/src/tests_export.rs+++ b/crates/engine/src/tests_export.rs@@ -682,11 +682,34 @@ fn remove_location_refuses_original_with_embedded_place_names() {};assert_eq!(place_name, Some(value), "{name} fixture should be parsed");let error = export_photo(&mut session, photo_id, &options, 1).err().expect("embedded place name should refuse Original export");- assert!(error.contains("place names") && error.contains("export as JPEG"), "{name}: {error}");+ assert!(error.contains("place names") && error.contains("export as JPEG or TIFF"), "{name}: {error}");}let _ = std::fs::remove_dir_all(&dir);}+#[test]+fn remove_location_refuses_original_with_unreadable_non_psd_xmp() {+ let dir = temp_dir("export-noloc-malformed-xmp");+ let path = dir.join("Unreadable.jpg");+ let pixels = [96u8; 12];+ let image = lightcraft_codecs::EncodeImage::new(2, 2, 3, lightcraft_codecs::Samples::U8(&pixels));+ let xmp = "<x:xmpmeta><broken";+ let encoded = lightcraft_codecs::EncodeMeta { xmp: Some(xmp), ..Default::default() };+ let bytes = lightcraft_codecs::encode_jpeg(&image, 90, lightcraft_codecs::ChromaSubsampling::S444, &encoded).unwrap();+ assert!(lightcraft_meta::parse_xmp(xmp).is_err(), "fixture XMP should be malformed");+ let metadata = lightcraft_meta::try_extract(&bytes).unwrap();+ assert!(metadata.gps.is_none() && metadata.city.is_none(), "best-effort extraction omits malformed XMP");+ std::fs::write(&path, bytes).unwrap();++ let mut session = Session::new().with_fs();+ session.execute("library.import", &json!({"paths": [path.to_string_lossy()]})).unwrap();+ let id = session.catalog.photos().next().unwrap().id;+ let options = ExportOptions { format: ExportFormat::Original, remove_location: true, ..Default::default() };+ let error = export_photo(&mut session, id, &options, 1).err().expect("unreadable XMP must not pass location removal");+ assert!(error.contains("can't verify location metadata") && error.contains("malformed embedded XMP"), "{error}");+ let _ = std::fs::remove_dir_all(&dir);+}+#[test]fn remove_location_original_place_refusal_writes_no_files() {use crate::export::{Destination, prepare_batch, run_batch};diff --git a/docs/whats-new.md b/docs/whats-new.mdindex 92a640d56..52ae9a2b8 100644--- a/docs/whats-new.md+++ b/docs/whats-new.md@@ -3,7 +3,7 @@## 2026-10-24### Original export checks embedded place names when removing location-- Original copies are refused when “Remove Location Info” is enabled and the source contains GPS or a nonblank sublocation, city, state or country. Use a rendered format or DNG to remove that embedded location.+- Original copies are refused when “Remove Location Info” is enabled and the source contains GPS or a nonblank sublocation, city, state or country. Use JPEG or TIFF for rendered output; DNG is available for raw photos.### Relative-date filters and smart albums follow the clock- A current view or source count using “in the last” rules now refreshes when the session clock moves into a new