[domistream] Tests: closed XML depth bomb under the size cap

xml_depth_bomb_does_not_recurse: the closed half was 300 000 tag pairs
(2.1 MB), over MAX_XML_BYTES, so its `s.len() < MAX_XML_BYTES * 2` assert
failed and the depth check under it never ran (the protocol engineer was
right). Now 100 000 opens + 100 000 closes (about 0.7 MB): within the size
cap, it must be refused as TooLarge { max: MAX_XML_DEPTH }, without
recursion. The open-tags half is unchanged.
This commit is contained in:
2026-11-26 03:53:14 +01:00
parent 6f13976ba5
commit d62aa8f581
+9 -7
View File
@@ -166,13 +166,15 @@ fn xml_depth_bomb_does_not_recurse() {
s.push_str(&"<a>".repeat(300_000)); s.push_str(&"<a>".repeat(300_000));
assert!(s.len() < MAX_XML_BYTES); assert!(s.len() < MAX_XML_BYTES);
assert_cap!(xml::parse(s.as_bytes()), MAX_XML_DEPTH); assert_cap!(xml::parse(s.as_bytes()), MAX_XML_DEPTH);
// Same with the closing tags present. // A closed, well-formed bomb that fits under the size cap (100 000 opens + 100 000 closes, about 0.7 MB): still
s.push_str(&"</a>".repeat(300_000)); // refused at depth 9, never parsed by recursion. (The earlier 300 000-pair version was 2.1 MB, over the size
s.push_str("</root>"); // cap, so its depth check never ran: ruled wrong 2026-11-26.)
assert!(s.len() < MAX_XML_BYTES * 2); let mut closed = String::from("<root status_code=\"200\">");
if s.len() <= MAX_XML_BYTES { closed.push_str(&"<a>".repeat(100_000));
assert_cap!(xml::parse(s.as_bytes()), MAX_XML_DEPTH); closed.push_str(&"</a>".repeat(100_000));
} closed.push_str("</root>");
assert!(closed.len() <= MAX_XML_BYTES, "{} bytes must fit the size cap", closed.len());
assert_cap!(xml::parse(closed.as_bytes()), MAX_XML_DEPTH);
} }
#[test] #[test]