Ignore processing-instruction decoys in Camera metadata

This commit is contained in:
yoriswind committed 2026-11-28 10:11:20 -08:00
1 parent 05bdefdeb1
commit f989c76e45
2 files changed
+13 -5

No files matched your search

+6 -4
View File
@@ -106,13 +106,13 @@ fn rights_marked(xmp: &str) -> Option<&str> {
// The existing Marked path retains its quote/whitespace and rewrite-span behavior.
fn marked_attr(xmp: &str) -> Option<(usize, usize, &str)> {
tag_attr(xmp, "xmpRights:Marked")
tag_attr(xmp, "xmpRights:Marked", false)
}
/// Attribute form `prop="…"` with either quote and XML whitespace before the name and around `=`.
/// Only names inside a tag count, not text in another attribute's value, element text, a comment
/// or CDATA. The span includes the whitespace before the name, so rewriting removes what is read.
fn tag_attr<'a>(xmp: &'a str, prop: &str) -> Option<(usize, usize, &'a str)> {
fn tag_attr<'a>(xmp: &'a str, prop: &str, camera_only: bool) -> Option<(usize, usize, &'a str)> {
// The tab title asks every frame, and packets can be megabytes: walk only when the name is there.
if !xmp.contains(prop) {
return None;
@@ -124,7 +124,9 @@ fn tag_attr<'a>(xmp: &'a str, prop: &str) -> Option<(usize, usize, &'a str)> {
(_, Some(q)) => quote = (c != q).then_some(q),
(false, None) if c == b'<' => {
let rest = &xmp[i..];
let skip = [("<!--", "-->"), ("<![CDATA[", "]]>")].into_iter().find(|(open, _)| rest.starts_with(open));
let skip = [("<!--", "-->"), ("<![CDATA[", "]]>"), ("<?", "?>")]
.into_iter()
.find(|(open, _)| rest.starts_with(open) && (camera_only || *open != "<?"));
match skip {
Some((_, close)) => i += rest.find(close).map_or(rest.len(), |e| e + close.len()) - 1,
None => in_tag = true,
@@ -271,7 +273,7 @@ fn date_text(s: &str) -> String {
fn xmp_value(x: &str, prop: &str) -> Option<String> {
let v = match find_element(x, prop) {
Some((_, _, inner)) => li_values(inner).into_iter().next(),
None => tag_attr(x, prop).map(|(_, _, v)| xml_unescape(v)),
None => tag_attr(x, prop, true).map(|(_, _, v)| xml_unescape(v)),
}?;
let v = v.trim().to_string();
(!v.is_empty()).then_some(v)
@@ -439,7 +439,7 @@ fn xmp_attribute_forms_supply_camera_values_without_changing_basic_behavior() {
let other = if quote == '"' { '\'' } else { '"' };
let note = format!("fixture:note={other} aux:OwnerName={quote}quoted-decoy{quote}{other}");
let packet = format!(
r#"<x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><!-- aux:OwnerName={quote}comment-decoy{quote} --><rdf:Description rdf:about="" xmlns:aux="http://ns.adobe.com/exif/1.0/aux/" xmlns:tiff="http://ns.adobe.com/tiff/1.0/" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" xmlns:xmpRights="http://ns.adobe.com/xap/1.0/rights/" xmlns:fixture="https://example.invalid/metadata-fixture/" {note}{before}aux:OwnerName{around}={around}{quote}Ada &amp; Co{quote}{before}tiff:Make{around}={around}{quote}Fixture make{quote}{before}photoshop:AuthorsPosition{around}={around}{quote}Old role{quote}{before}xmpRights:Marked{around}={around}{quote}True{quote} fixture:opaque="preserve-me"/></rdf:RDF></x:xmpmeta>"#
r#"<?fixture aux:OwnerName='pi-owner' tiff:Make='pi-make'?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><!-- aux:OwnerName={quote}comment-decoy{quote} --><rdf:Description rdf:about="" xmlns:aux="http://ns.adobe.com/exif/1.0/aux/" xmlns:tiff="http://ns.adobe.com/tiff/1.0/" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" xmlns:xmpRights="http://ns.adobe.com/xap/1.0/rights/" xmlns:fixture="https://example.invalid/metadata-fixture/" {note}{before}aux:OwnerName{around}={around}{quote}Ada &amp; Co{quote}{before}tiff:Make{around}={around}{quote}Fixture make{quote}{before}photoshop:AuthorsPosition{around}={around}{quote}Old role{quote}{before}xmpRights:Marked{around}={around}{quote}True{quote} fixture:opaque="preserve-me"/></rdf:RDF></x:xmpmeta>"#
);
let mut session = photocraft_engine::Session::new();
session.execute("file.new", json!({"width": 64, "height": 48})).unwrap();
@@ -469,4 +469,10 @@ fn xmp_attribute_forms_supply_camera_values_without_changing_basic_behavior() {
assert!(xmp.contains("fixture:opaque=\"preserve-me\""));
assert!(xmp.contains(&format!("<!-- aux:OwnerName={quote}comment-decoy{quote} -->")));
}
// The pre-existing Marked scanner also reads PI pseudo-attributes. Camera-only correction
// must not silently change that Basic behavior while its separate scope is under review.
let marked = photocraft_engine::file_cmds::read_file_info(Some(
r#"<?fixture xmpRights:Marked='False'?><rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xmpRights="http://ns.adobe.com/xap/1.0/rights/" xmpRights:Marked="True"/>"#,
));
assert_eq!(marked["copyrightStatus"], "publicDomain", "keep pre-PR Marked behavior");
}