From 4c3fcafa01bbc1eeb158b70812ecc78b6df1ca38 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 24 Nov 2026 22:33:02 +0000 Subject: [PATCH] svg test: the entity expansion bomb at a limit 256 times smaller --- crates/svg/src/guard.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/svg/src/guard.rs b/crates/svg/src/guard.rs index e2a11ae6a4..c9575f5992 100644 --- a/crates/svg/src/guard.rs +++ b/crates/svg/src/guard.rs @@ -487,7 +487,10 @@ mod tests { #[test] fn a_repeated_large_entity_is_too_large_and_a_namespace_entity_is_not() { - let big = "x".repeat(1 << 20); + // (the limit is passed in: the same arithmetic as `MAX_ENTITY_EXPANSION` over entities 256 times smaller, which + // only expand to 16 references' worth, so the strings the test builds and scans stay small) + let big = "x".repeat(1 << 16); + let expansion_too_large = |svg: &str| entities_expand_past(svg, 16 << 16); let refs = "&a;".repeat(20); let bomb = format!("]>"); assert!(expansion_too_large(&bomb)); @@ -500,6 +503,7 @@ mod tests { let ampersands = format!("]>", "&".repeat(1 << 20)); let start = std::time::Instant::now(); assert!(!expansion_too_large(&ersands)); + eprintln!("DIAG svg ampersand run read in {:?}", start.elapsed()); // A quadratic read would take hours; the bound is loose for a loaded machine. assert!(start.elapsed() < std::time::Duration::from_secs(120), "{:?}", start.elapsed()); }