fix(xfa): classify shared namespace admission as too large

This commit is contained in:
FredApps committed 2026-11-18 18:07:30 +01:00
1 parent 39b3f45a9d
commit fe16ea4834
2 files changed
+18 -1

No files matched your search

+9 -1
View File
@@ -193,7 +193,15 @@ pub fn parse_data_file(text: &str, expect_root: Option<&str>) -> Result<Vec<Impo
return Err(XfaError::TooLarge(format!("the data file nests more than {MAX_IMPORT_DEPTH} levels deep")));
}
let opts = crate::xml::ParsingOptions { allow_dtd: false, nodes_limit: MAX_NODES };
let parsed = crate::xml::Document::parse_with_options(text, opts).map_err(|e| XfaError::Malformed(format!("the data file is not XML: {e}")))?;
let parsed = crate::xml::Document::parse_with_options(text, opts).map_err(|e| {
// The pinned shared parser exposes string errors. Its namespace-copy admission
// limit is a resource refusal, not malformed XML; keep every other error distinct.
if e == "namespace retention budget exceeded" {
XfaError::TooLarge(format!("the data file exceeds the XML namespace retention budget: {e}"))
} else {
XfaError::Malformed(format!("the data file is not XML: {e}"))
}
})?;
let root = parsed.root_element();
let local = root.tag_name().name();
let in_xfa = |n: &crate::xml::Node| n.tag_name().namespace().is_none_or(|ns| ns == XFA_DATA_NS);
+9
View File
@@ -5239,6 +5239,15 @@ fn an_inherited_namespace_does_not_multiply_an_import() {
}
}
#[test]
fn data_import_keeps_malformed_xml_distinct_from_namespace_limits() {
use crate::data::parse_data_file;
for xml in ["<form1><a></form1>", "<form1><p:a/></form1>"] {
assert!(matches!(parse_data_file(xml, None), Err(XfaError::Malformed(_))), "{xml}");
}
let nodes = parse_data_file("<form1 xmlns:p='urn:small'><p:a>value</p:a></form1>", None).unwrap();
assert!(!nodes.is_empty());
}
/// A long data name with a high index is not copied into every sibling created before it.
#[test]
fn long_names_repeated_by_an_index_are_capped() {