From c03ba68ab363bcf337a5f2c9548ead0b941b427f Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Wed, 18 Nov 2026 14:36:07 +0700 Subject: [PATCH] fix(xfa): reject repeated leading BOM before parsing spans (#2176) --- crates/xfa/src/xml.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/xfa/src/xml.rs b/crates/xfa/src/xml.rs index 7afab7600..7d6dd8193 100644 --- a/crates/xfa/src/xml.rs +++ b/crates/xfa/src/xml.rs @@ -194,6 +194,10 @@ impl Document { // quick-xml excludes a leading UTF-8 BOM from its buffer positions. // Parse it explicitly so every stored range still addresses the original input. let input = text.strip_prefix('\u{feff}').unwrap_or(text); + // A second U+FEFF is content outside the root, not another encoding marker. + if input.starts_with('\u{feff}') { + return Err("multiple leading XML byte-order marks".to_string()); + } let source_offset = text.len() - input.len(); let mut events = opts.events(input.as_bytes()); let mut nodes: Vec = Vec::new(); @@ -435,6 +439,15 @@ mod tests { } } + #[test] + fn repeated_leading_bom_is_rejected_before_event_parsing() { + for prefix in ["\u{feff}\u{feff}", "\u{feff}\u{feff}\u{feff}"] { + for body in ["<é/>", "<é>text"] { + assert!(Document::parse(&format!("{prefix}{body}")).is_err()); + } + } + } + #[test] fn inherited_namespace_copies_obey_aggregate_byte_admission() { let uri = format!("urn:{}", "x".repeat(124));