From d62aa8f581631e7e5810a9609177d2e293175ca1 Mon Sep 17 00:00:00 2001 From: mnovak Date: Thu, 26 Nov 2026 03:53:14 +0100 Subject: [PATCH] [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. --- crates/domistream/tests/http.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/domistream/tests/http.rs b/crates/domistream/tests/http.rs index d7e922b..477981f 100644 --- a/crates/domistream/tests/http.rs +++ b/crates/domistream/tests/http.rs @@ -166,13 +166,15 @@ fn xml_depth_bomb_does_not_recurse() { s.push_str(&"".repeat(300_000)); assert!(s.len() < MAX_XML_BYTES); assert_cap!(xml::parse(s.as_bytes()), MAX_XML_DEPTH); - // Same with the closing tags present. - s.push_str(&"".repeat(300_000)); - s.push_str(""); - assert!(s.len() < MAX_XML_BYTES * 2); - if s.len() <= MAX_XML_BYTES { - assert_cap!(xml::parse(s.as_bytes()), MAX_XML_DEPTH); - } + // A closed, well-formed bomb that fits under the size cap (100 000 opens + 100 000 closes, about 0.7 MB): still + // refused at depth 9, never parsed by recursion. (The earlier 300 000-pair version was 2.1 MB, over the size + // cap, so its depth check never ran: ruled wrong 2026-11-26.) + let mut closed = String::from(""); + closed.push_str(&"".repeat(100_000)); + closed.push_str(&"".repeat(100_000)); + closed.push_str(""); + 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]