PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Integration: #7976 bound the ';' search in xml_unescape to 13 bytes
aionggd8acd0579a25
diff --git a/crates/engine/src/file_cmds.rs b/crates/engine/src/file_cmds.rsindex 661fbba50..db8a66b54 100644--- a/crates/engine/src/file_cmds.rs+++ b/crates/engine/src/file_cmds.rs@@ -707,7 +707,7 @@ fn xml_unescape(s: &str) -> String {while let Some(i) = rest.find('&') {out.push_str(&rest[..i]);rest = &rest[i..];- let decoded = rest.find(';').filter(|&e| e <= 12).and_then(|e| {+ let decoded = rest.as_bytes().iter().take(13).position(|&b| b == b';').and_then(|e| {let c = match &rest[1..e] {"lt" => '<',"gt" => '>',diff --git a/crates/engine/tests/xmp_charref.rs b/crates/engine/tests/xmp_charref.rsindex 5f167e8c4..a4b98da4e 100644--- a/crates/engine/tests/xmp_charref.rs+++ b/crates/engine/tests/xmp_charref.rs@@ -8,3 +8,17 @@ fn numeric_character_references_are_decoded() {let info = read_file_info(Some(xmp));assert_eq!(info["description"], "Line one\nLine two © & co A &");}++/// Many `&` with no `;` near them stay literal, and are scanned a bounded distance each (a+/// multi-megabyte XMP once made this quadratic).+#[test]+fn a_long_run_of_ampersands_without_semicolons_is_left_unchanged() {+ let run = "&".repeat(200_000);+ let xmp = format!(+ "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF><rdf:Description>\+ <dc:description><rdf:Alt><rdf:li xml:lang=\"x-default\">{run}</rdf:li></rdf:Alt></dc:description>\+ </rdf:Description></rdf:RDF></x:xmpmeta>"+ );+ let info = read_file_info(Some(&xmp));+ assert_eq!(info["description"], run.as_str());+}