From 240cbf1f3bb516f66b43dbdb33914f9515f2d069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 04:56:50 -0500 Subject: [PATCH 1/5] fix(render): reading an SVG's style text and element attributes is bounded before the parsers that go quadratic on them (#2800) --- crates/render/src/picture/svg.rs | 108 +++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/crates/render/src/picture/svg.rs b/crates/render/src/picture/svg.rs index 2dc44450bf..0e72a74b12 100644 --- a/crates/render/src/picture/svg.rs +++ b/crates/render/src/picture/svg.rs @@ -67,6 +67,20 @@ const ARC_CUBICS: f64 = 200.0; /// attribute's value matched costs a step each 64 bytes too, and each node walked back past to a /// sibling one. Icons take thousands of steps. pub(super) const CSS_STEPS: u64 = 4_000_000; +/// The most that reading an SVG's style sheets and `style` attributes may come to, in units of a +/// declaration scanned a byte ([`style_units`]): simplecss reads each declaration's value to an +/// end that fails (`consume_term`) and works out where that was by scanning the text from its +/// start, so a sheet costs its declarations times its length, and is read twice (here and by usvg). +/// Measured: 10,000 rules of 199 KB 0.64 s, 40,000 of 829 KB 10.5 s, one rule of 20,000 +/// declarations 1.4 s, and 40 million units 46 ms to read whole, so ~1.2 ns a unit: at most ~20 +/// ms. Icons come to a few million. +pub(super) const STYLE_UNITS: u64 = 16_000_000; +/// The most that reading an SVG's tags may come to, in pairs of attributes of one element +/// ([`attribute_pairs`]): roxmltree checks each attribute of an element against those before it +/// for a duplicate, so an element's cost is the square of its attributes, and nothing else +/// limits them. Measured: 2,000 attributes on one element 2.7 ms, some 0.7 ns a pair, so at most +/// ~11 ms (4,000 attributes). Elements have a dozen. +pub(super) const ATTRIBUTE_PAIRS: u64 = 16_000_000; /// The most XML nodes (elements, text, comments) read before giving up, a bound on reading the /// text itself: [`ELEMENTS`] and the text and spaces between them. pub(super) const XML_NODES: u32 = 4 * ELEMENTS as u32; @@ -86,6 +100,10 @@ const STOPS_PER_UNIT: u64 = 16; /// run ([`Refusal::PastRun`]) when below [`CSS_STEPS`]; `matched` is set to the steps it took, /// refused or not, which its length doesn't bound, for the run to be charged them. pub(super) fn read(text: &str, cap: u64, matched: &mut u64) -> Result { + // Before roxmltree checks each attribute of a tag against those before it. + if attribute_pairs(text) > ATTRIBUTE_PAIRS { + return Err(Refusal::TooMuch); + } let xml = roxmltree::ParsingOptions { allow_dtd: true, nodes_limit: XML_NODES, ..Default::default() }; let doc = roxmltree::Document::parse_with_options(text, xml).map_err(|e| match e { roxmltree::Error::NodesLimitReached => Refusal::TooNested, @@ -101,6 +119,10 @@ pub(super) fn read(text: &str, cap: u64, matched: &mut u64) -> Result STYLE_UNITS { + return Err(Refusal::TooMuch); + } with_sheet(&doc, |sheet| { let (_, by_sheet) = elements(&doc, sheet, cap, matched)?; if nested_markers(&doc, &by_sheet) { Err(Refusal::TooMuch) } else { Ok(()) } @@ -322,6 +344,34 @@ impl simplecss::Element for Stepped<'_, '_> { } } +/// What reading `doc`'s style sheets and `style` attributes comes to, in [`STYLE_UNITS`]: each one's +/// declarations (the `;` and `}` that end them, more than they are, never fewer) times its length, +/// all added up. +fn style_units(doc: &roxmltree::Document) -> u64 { + let declarations = |text: &str| text.bytes().filter(|b| matches!(b, b';' | b'}')).count() as u64; + let mut units = 0u64; + for n in doc.descendants() { + if n.has_tag_name("style") { + let sheet = sheet_of(n); + units = units.saturating_add(declarations(&sheet).saturating_mul(sheet.len() as u64)); + } + if let Some(style) = n.attribute("style") { + units = units.saturating_add((declarations(style) + 1).saturating_mul(style.len() as u64)); + } + } + units +} + +/// What reading `text`'s tags comes to, in [`ATTRIBUTE_PAIRS`]: the square of the `=` in each piece +/// of it between `<`s, added up. A `<` isn't in a tag's attributes in XML that reads (roxmltree +/// stops at it before it checks them), so each tag is one piece, and an attribute is one `=` of it, +/// perhaps more (in a value or in the text after the tag): more than it is, never fewer. +fn attribute_pairs(text: &str) -> u64 { + text.split('<') + .map(|piece| piece.bytes().filter(|b| *b == b'=').count() as u64) + .fold(0u64, |pairs, n| pairs.saturating_add(n.saturating_mul(n))) +} + /// `f` of `doc`'s style sheets, read once as usvg reads them (`resolve_css`), every `{deep}"))).err(), Some(Refusal::TooMuch)); } + /// A style sheet or a `style` attribute is read within a bound before simplecss reads it, + /// whose cost is the square of its declarations (#2800). + #[test] + fn style_text_is_read_within_its_bound() { + let rules = |n: usize| (0..n).map(|i| format!(".c{i} {{ fill: red }}")).collect::(); + let declarations = |n: usize| "fill: red; ".repeat(n); + // 40,000 rules (829 KB) took 10 s to read: refused, and never matched. + let mut matched = 0; + let sheet = svg(&format!("", rules(40_000))); + assert_eq!(super::read(&sheet, CSS_STEPS, &mut matched).err(), Some(Refusal::TooMuch)); + assert_eq!(matched, 0, "refused before its rules were matched"); + // One `style` attribute of 20,000 declarations, as long a time. + let one = svg(&format!(r#""#, declarations(20_000))); + assert_eq!(read(&one).err(), Some(Refusal::TooMuch)); + // The bound is on all of them together: each of these costs little. + let many = svg(&(0..3000).map(|_| format!(r#""#, declarations(100))).collect::()); + assert_eq!(read(&many).err(), Some(Refusal::TooMuch)); + // An icon's own: 200 rules, a few declarations a `style`, a comment as long as can be. + assert!(read(&svg(&format!("", rules(200)))).is_ok()); + assert!(read(&svg(&format!(r#""#, declarations(10)))).is_ok()); + let comment = format!("", "x".repeat(400_000)); + assert!(read(&svg(&comment)).is_ok(), "a comment's bytes aren't declarations"); + // The edge: the most rules that are under it, and one more. + let units = |n: usize| style_units(&roxmltree::Document::parse(&svg(&format!("", rules(n)))).unwrap()); + let edge = (1..).find(|n| units(*n) > STYLE_UNITS).unwrap(); + let rect = r#""#; + assert!(read(&svg(&format!("{rect}", rules(edge - 1)))).is_ok()); + assert_eq!(read(&svg(&format!("{rect}", rules(edge)))).err(), Some(Refusal::TooMuch)); + } + + /// An element's attributes are read within a bound before roxmltree reads them, which checks + /// each of its attributes against all those before it (#2800). + #[test] + fn an_elements_attributes_are_read_within_their_bound() { + let attributes = |n: usize| (0..n).map(|i| format!(r#" a{i}="1""#)).collect::(); + assert_eq!(read(&svg(&format!(r#""#, attributes(100_000)))).err(), Some(Refusal::TooMuch)); + // A dozen on each of thousands, and a few dozen on one, are an icon's. + let rects = (0..9000).map(|_| r#""#).collect::(); + assert!(read(&svg(&rects)).is_ok()); + assert!(read(&svg(&format!(r#""#, attributes(40)))).is_ok()); + // The `=` of the text between tags counts too, which only ever makes it count more. + assert!(read(&svg(&format!("{}", "a=b ".repeat(1000)))).is_ok()); + assert_eq!(read(&svg(&format!("{}", "a=b ".repeat(5000)))).err(), Some(Refusal::TooMuch)); + // The bound is on the tags: a `<` in a value isn't XML that reads. + assert_eq!(read(&svg(&format!(r#""#, attributes(100)))).err(), Some(Refusal::NotSvg)); + } + + /// usvg takes from a `style` attribute only the presentation properties, which a radius isn't: + /// one set there is not read, so there is nothing to look at in it (guards an update of usvg). + #[test] + fn a_radius_in_a_style_is_not_one_usvg_reads() { + let tree = read(&svg(r#""#)).unwrap(); + let width = tree.root().abs_bounding_box().map_or(0.0, |b| b.width()); + assert!((width - 10.0).abs() < 0.1, "{width}"); + let sheet = read(&svg(r#""#)).unwrap(); + assert!((sheet.root().abs_bounding_box().map_or(0.0, |b| b.width()) - 10.0).abs() < 0.1); + } + /// Matching stops once the steps taken for all the elements matched so far pass /// [`CSS_STEPS`], not one element's: a selector of four descendants on 60 nested groups /// takes each of them at most C(60, 4) steps, under the cap, and all of them C(61, 5) (#2713). From adf91c55d24d12835e41a360819f38f562104dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 05:44:08 -0500 Subject: [PATCH 2/5] fix(render): an SVG refused for its style text or attributes says that, not that it has more to draw (#2800) --- crates/engine/src/project.rs | 10 ++++++++-- crates/engine/src/tests.rs | 4 ++++ crates/render/src/picture.rs | 10 +++++++++- crates/render/src/picture/svg.rs | 24 ++++++++++++++---------- crates/ui-egui/src/markerpick.rs | 4 ++++ docs/user-guide/cartography.md | 4 +++- 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index e48df5377f..971b16fe34 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -2241,11 +2241,12 @@ pub(crate) fn picture_notices_by<'a>( *seen.borrow_mut().entry(p).or_insert_with(|| check(p)) }; // The names with an image refused so, by each refusal in `WHY`, in the order their notices go. - const WHY: [MarkerRefusal; 10] = [ + const WHY: [MarkerRefusal; 11] = [ MarkerRefusal::NotAnImage, MarkerRefusal::TooManyBytes, MarkerRefusal::TooManyPixels, MarkerRefusal::TooMuchToDraw, + MarkerRefusal::SvgTooMuchToRead, MarkerRefusal::SvgTooNested, MarkerRefusal::SvgUnknownRadius, MarkerRefusal::SvgTooSmall, @@ -2294,7 +2295,8 @@ pub(crate) fn picture_notices_by<'a>( ], )); } - let [not_images, too_long, too_large, too_much, too_nested, unknown_radius, too_small, not_utf8, filtered, past_run] = &bad; + let [not_images, too_long, too_large, too_much, too_much_to_read, too_nested, unknown_radius, too_small, not_utf8, filtered, past_run] = + &bad; if !not_images.is_empty() { notices.push(NoticeText::format( "Image markers in {names} aren't PNG, JPEG or SVG images and are drawn as circles", @@ -2321,6 +2323,10 @@ pub(crate) fn picture_notices_by<'a>( } // Each SVG's own cause (#2713), its figures as the renderer's phrase gives them. for (names, what) in [ + ( + too_much_to_read, + "Image markers in {names} are SVGs whose style sheets or element attributes take more to read than RustGIS allows and are drawn as circles", + ), ( too_nested, "Image markers in {names} are SVGs with more than 40,000 XML nodes or nested deeper than 64 levels and are drawn as circles", diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index af5180eb7a..f7f32e90d3 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -2747,6 +2747,10 @@ fn svg_image_markers_that_dont_draw_are_said_with_why() { "Image markers in \"Cities\", \"Rivers\" are SVGs with filters, text, images, animation or links to other files, which RustGIS doesn't draw in marker images, and are drawn as circles", ), (MarkerRefusal::TooManyBytes, "Image markers in \"Cities\", \"Rivers\" are longer than 2 MiB as base64 and are drawn as circles"), + ( + MarkerRefusal::SvgTooMuchToRead, + "Image markers in \"Cities\", \"Rivers\" are SVGs whose style sheets or element attributes take more to read than RustGIS allows and are drawn as circles", + ), ( MarkerRefusal::SvgTooNested, "Image markers in \"Cities\", \"Rivers\" are SVGs with more than 40,000 XML nodes or nested deeper than 64 levels and are drawn as circles", diff --git a/crates/render/src/picture.rs b/crates/render/src/picture.rs index 0e643e1bf2..9b2486159b 100644 --- a/crates/render/src/picture.rs +++ b/crates/render/src/picture.rs @@ -81,6 +81,9 @@ pub enum MarkerRefusal { /// It is an SVG with more to draw than [`MARKER_PIXELS`] (in the units of the renderer's SVG /// count, `svg::work`), or more elements than `svg::ELEMENTS` (10,000). TooMuchToDraw, + /// It is an SVG whose style sheets and `style` attributes, or whose elements' attributes, take + /// more to read than `svg::STYLE_UNITS` and `svg::ATTRIBUTE_PAIRS` allow. + SvgTooMuchToRead, /// It is an SVG with more XML nodes than `svg::XML_NODES` (40,000) or nested deeper than /// `svg::DEPTH` (64). SvgTooNested, @@ -136,6 +139,7 @@ refusal_phrases! { TooManyBytes => "is longer than 2 MiB as base64", TooManyPixels => "has more pixels than 2048 × 2048", TooMuchToDraw => "is an SVG with more to draw than a 2048 × 2048 image", + SvgTooMuchToRead => "is an SVG whose style sheets or element attributes take more to read than RustGIS allows", SvgTooNested => "is an SVG with more than 40,000 XML nodes or nested deeper than 64 levels", SvgUnknownRadius => "is an SVG with a radius whose size RustGIS can't know (in em or ex, or in % of a size in em or ex, or of a nested size in % over 100%)", SvgTooSmall => "is an SVG too small to draw", @@ -371,6 +375,7 @@ impl From for MarkerRefusal { svg::Refusal::NotSvg => MarkerRefusal::NotAnImage, svg::Refusal::TooMuch => MarkerRefusal::TooMuchToDraw, svg::Refusal::PastRun => MarkerRefusal::PastRunPixels, + svg::Refusal::TooMuchToRead => MarkerRefusal::SvgTooMuchToRead, svg::Refusal::TooNested => MarkerRefusal::SvgTooNested, svg::Refusal::UnknownRadius => MarkerRefusal::SvgUnknownRadius, svg::Refusal::Undrawn => MarkerRefusal::SvgUndrawn, @@ -776,6 +781,7 @@ mod tests { TooManyBytes, TooManyPixels, TooMuchToDraw, + SvgTooMuchToRead, SvgTooNested, SvgUnknownRadius, SvgTooSmall, @@ -784,7 +790,7 @@ mod tests { PastRunPixels ] .map(MarkerRefusal::lasts), - [true, true, true, true, true, true, true, true, true, false] + [true, true, true, true, true, true, true, true, true, true, false] ); // A kept image the run's spent budget refuses is kept as it is; one refused for itself // isn't; one that draws is. @@ -903,6 +909,8 @@ mod tests { (long_png, TooManyBytes), (svg(&deep), SvgTooNested), (svg(&nodes), SvgTooNested), + // Its own cause (#2800), not "more to draw": 20,000 declarations in a `style` take too long to read. + (svg(&format!(r#""#, "fill: red; ".repeat(20_000))), SvgTooMuchToRead), (svg(r#""#), SvgUnknownRadius), (svg(r#""#), SvgUnknownRadius), // A radius in % of a size in em or ex with no view box, or of a nested one past 100%. diff --git a/crates/render/src/picture/svg.rs b/crates/render/src/picture/svg.rs index 0e72a74b12..b11f5561ee 100644 --- a/crates/render/src/picture/svg.rs +++ b/crates/render/src/picture/svg.rs @@ -32,6 +32,9 @@ pub(super) enum Refusal { NotSvg, /// It has more to draw than the cap given, or more elements than [`ELEMENTS`]. TooMuch, + /// Its style sheets and `style` attributes come to more than [`STYLE_UNITS`], or the attributes + /// of its elements to more than [`ATTRIBUTE_PAIRS`]: more to read than the readers do in time. + TooMuchToRead, /// It has more XML nodes than [`XML_NODES`], or nests deeper than [`DEPTH`]. TooNested, /// A shape's radius may be any size: in em or ex, font sizes, which no font is loaded to give, @@ -102,7 +105,7 @@ const STOPS_PER_UNIT: u64 = 16; pub(super) fn read(text: &str, cap: u64, matched: &mut u64) -> Result { // Before roxmltree checks each attribute of a tag against those before it. if attribute_pairs(text) > ATTRIBUTE_PAIRS { - return Err(Refusal::TooMuch); + return Err(Refusal::TooMuchToRead); } let xml = roxmltree::ParsingOptions { allow_dtd: true, nodes_limit: XML_NODES, ..Default::default() }; let doc = roxmltree::Document::parse_with_options(text, xml).map_err(|e| match e { @@ -121,7 +124,7 @@ pub(super) fn read(text: &str, cap: u64, matched: &mut u64) -> Result STYLE_UNITS { - return Err(Refusal::TooMuch); + return Err(Refusal::TooMuchToRead); } with_sheet(&doc, |sheet| { let (_, by_sheet) = elements(&doc, sheet, cap, matched)?; @@ -1396,7 +1399,8 @@ mod tests { assert!(read(&svg(&format!("{}", rules(200), rects(2500)))).is_ok()); // 9,998 rects, the svg and the style come to [`ELEMENTS`], two steps a rule each: the cap. assert!(read(&svg(&format!("{}", rules(200), rects(9998)))).is_ok()); - assert_eq!(read(&svg(&format!("{}", rules(2000), rects(2000)))).err(), Some(Refusal::TooMuch)); + // (A sheet this long is under [`STYLE_UNITS`]: it is the steps that refuse it, not its text.) + assert_eq!(read(&svg(&format!("{}", rules(800), rects(9000)))).err(), Some(Refusal::TooMuch)); // usvg reads what a `` repeats again for each ``, and matches the rules again: a // rect used 1,000 times, under a sheet of 1,000 rules. let used = format!( @@ -1404,7 +1408,7 @@ mod tests { r##""##.repeat(10), r##""##.repeat(100) ); - assert_eq!(read(&svg(&format!("{used}", rules(1000)))).err(), Some(Refusal::TooMuch)); + assert_eq!(read(&svg(&format!("{used}", rules(900)))).err(), Some(Refusal::TooMuch)); assert!(read(&svg(&format!("{used}", rules(20)))).is_ok()); // Each descendant in a selector tries every element above: a few of them, 40 levels down. let deep = format!("{}{}", "".repeat(40), "".repeat(40)); @@ -1421,14 +1425,14 @@ mod tests { // 40,000 rules (829 KB) took 10 s to read: refused, and never matched. let mut matched = 0; let sheet = svg(&format!("", rules(40_000))); - assert_eq!(super::read(&sheet, CSS_STEPS, &mut matched).err(), Some(Refusal::TooMuch)); + assert_eq!(super::read(&sheet, CSS_STEPS, &mut matched).err(), Some(Refusal::TooMuchToRead)); assert_eq!(matched, 0, "refused before its rules were matched"); // One `style` attribute of 20,000 declarations, as long a time. let one = svg(&format!(r#""#, declarations(20_000))); - assert_eq!(read(&one).err(), Some(Refusal::TooMuch)); + assert_eq!(read(&one).err(), Some(Refusal::TooMuchToRead)); // The bound is on all of them together: each of these costs little. let many = svg(&(0..3000).map(|_| format!(r#""#, declarations(100))).collect::()); - assert_eq!(read(&many).err(), Some(Refusal::TooMuch)); + assert_eq!(read(&many).err(), Some(Refusal::TooMuchToRead)); // An icon's own: 200 rules, a few declarations a `style`, a comment as long as can be. assert!(read(&svg(&format!("", rules(200)))).is_ok()); assert!(read(&svg(&format!(r#""#, declarations(10)))).is_ok()); @@ -1439,7 +1443,7 @@ mod tests { let edge = (1..).find(|n| units(*n) > STYLE_UNITS).unwrap(); let rect = r#""#; assert!(read(&svg(&format!("{rect}", rules(edge - 1)))).is_ok()); - assert_eq!(read(&svg(&format!("{rect}", rules(edge)))).err(), Some(Refusal::TooMuch)); + assert_eq!(read(&svg(&format!("{rect}", rules(edge)))).err(), Some(Refusal::TooMuchToRead)); } /// An element's attributes are read within a bound before roxmltree reads them, which checks @@ -1447,14 +1451,14 @@ mod tests { #[test] fn an_elements_attributes_are_read_within_their_bound() { let attributes = |n: usize| (0..n).map(|i| format!(r#" a{i}="1""#)).collect::(); - assert_eq!(read(&svg(&format!(r#""#, attributes(100_000)))).err(), Some(Refusal::TooMuch)); + assert_eq!(read(&svg(&format!(r#""#, attributes(100_000)))).err(), Some(Refusal::TooMuchToRead)); // A dozen on each of thousands, and a few dozen on one, are an icon's. let rects = (0..9000).map(|_| r#""#).collect::(); assert!(read(&svg(&rects)).is_ok()); assert!(read(&svg(&format!(r#""#, attributes(40)))).is_ok()); // The `=` of the text between tags counts too, which only ever makes it count more. assert!(read(&svg(&format!("{}", "a=b ".repeat(1000)))).is_ok()); - assert_eq!(read(&svg(&format!("{}", "a=b ".repeat(5000)))).err(), Some(Refusal::TooMuch)); + assert_eq!(read(&svg(&format!("{}", "a=b ".repeat(5000)))).err(), Some(Refusal::TooMuchToRead)); // The bound is on the tags: a `<` in a value isn't XML that reads. assert_eq!(read(&svg(&format!(r#""#, attributes(100)))).err(), Some(Refusal::NotSvg)); } diff --git a/crates/ui-egui/src/markerpick.rs b/crates/ui-egui/src/markerpick.rs index b943e3b3a6..fdcc54b742 100644 --- a/crates/ui-egui/src/markerpick.rs +++ b/crates/ui-egui/src/markerpick.rs @@ -94,6 +94,10 @@ impl MarkerImage { "This image can't be a marker: it is longer than {mib} MiB as base64; make it smaller", &[("mib", &(rustgis_engine::map::symbology::MAX_PICTURE_BYTES >> 20).to_string())], ), + MarkerRefusal::SvgTooMuchToRead => tl!( + "This image can't be a marker: it is an SVG whose style sheets or element attributes take more to read than RustGIS allows" + ) + .to_string(), MarkerRefusal::SvgTooNested => tl!( "This image can't be a marker: it is an SVG with more than 40,000 XML nodes or nested deeper than 64 levels" ) diff --git a/docs/user-guide/cartography.md b/docs/user-guide/cartography.md index 381a98b2ae..dde921b80a 100644 --- a/docs/user-guide/cartography.md +++ b/docs/user-guide/cartography.md @@ -112,7 +112,9 @@ paints, not its size: a few kilobytes of dashes finer than a pixel, or of see-th up, can take minutes. So one with more to draw than a 2048 × 2048 image isn't taken either, nor one past 10,000 elements or 200,000 points of its shapes once each `` is counted where it repeats, nor one with a marker on a shape inside another marker (drawn on each of its vertices -wherever it is). An arc is counted as the curves it is drawn with, more the larger its radius: +wherever it is), nor one whose style sheets and `style` attributes, or whose elements' attributes, +take more to read than a few milliseconds (a sheet of some 900 short rules, or 4,000 +attributes on one element). An arc is counted as the curves it is drawn with, more the larger its radius: one of more than 200 curves isn't taken, nor is a circle, an ellipse or a rounded corner whose radius is in em or ex, which may come to any size. A radius in % is counted as that share of the largest size the SVG gives itself; such a radius isn't taken either when the SVG's own width or From 8de6379777b835876fddaa4735e07ae64df81b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 05:53:07 -0500 Subject: [PATCH 3/5] test(render): an entity can't be a way round the attribute bound; read's doc names both new bounds (#2800) --- crates/render/src/picture/svg.rs | 29 +++++++++++++++++++++++------ docs/user-guide/cartography.md | 5 +++-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/crates/render/src/picture/svg.rs b/crates/render/src/picture/svg.rs index b11f5561ee..f793bfeb05 100644 --- a/crates/render/src/picture/svg.rs +++ b/crates/render/src/picture/svg.rs @@ -97,11 +97,12 @@ const NODE: u64 = 100; /// 695 ns a pixel, 100 stops 93 ns, 2 stops 21 ns), so each stop costs 1/16 of a unit a pixel. const STOPS_PER_UNIT: u64 = 16; -/// SVG text `text` read into a tree: within [`XML_NODES`], [`ELEMENTS`], [`POINTS`] and -/// [`CSS_STEPS`], its root an ``, with no images resolved and no files read. Matching its -/// style sheets ([`css_steps`]) stops at `cap` too, what the run has left, refused there for the -/// run ([`Refusal::PastRun`]) when below [`CSS_STEPS`]; `matched` is set to the steps it took, -/// refused or not, which its length doesn't bound, for the run to be charged them. +/// SVG text `text` read into a tree: within [`XML_NODES`], [`ELEMENTS`], [`POINTS`], [`CSS_STEPS`], +/// [`STYLE_UNITS`] and [`ATTRIBUTE_PAIRS`], its root an ``, with no images resolved and no +/// files read. Matching its style sheets ([`css_steps`]) stops at `cap` too, what the run has +/// left, refused there for the run ([`Refusal::PastRun`]) when below [`CSS_STEPS`]; `matched` is +/// set to the steps it took, refused or not, which its length doesn't bound, for the run to be +/// charged them. pub(super) fn read(text: &str, cap: u64, matched: &mut u64) -> Result { // Before roxmltree checks each attribute of a tag against those before it. if attribute_pairs(text) > ATTRIBUTE_PAIRS { @@ -356,7 +357,7 @@ fn style_units(doc: &roxmltree::Document) -> u64 { for n in doc.descendants() { if n.has_tag_name("style") { let sheet = sheet_of(n); - units = units.saturating_add(declarations(&sheet).saturating_mul(sheet.len() as u64)); + units = units.saturating_add((declarations(&sheet) + 1).saturating_mul(sheet.len() as u64)); } if let Some(style) = n.attribute("style") { units = units.saturating_add((declarations(style) + 1).saturating_mul(style.len() as u64)); @@ -1463,6 +1464,22 @@ mod tests { assert_eq!(read(&svg(&format!(r#""#, attributes(100)))).err(), Some(Refusal::NotSvg)); } + /// An entity can't expand to a tag (roxmltree refuses it), so the tags counted before reading are + /// the tags read (#2800): the way round the attribute bound the text count would leave (guards an + /// update of roxmltree). + #[test] + fn an_entity_of_a_tag_with_many_attributes_is_not_a_way_round_the_bound() { + let attributes = (0..2000).map(|i| format!(r#" a{i}="1""#)).collect::(); + let uses = "&t;".repeat(3000); + let text = format!( + r#"">]>{uses}"# + ); + let started = std::time::Instant::now(); + let refused = read(&text).err(); + assert_eq!(refused, Some(Refusal::NotSvg), "read whole in {:?}", started.elapsed()); + assert!(started.elapsed() < std::time::Duration::from_secs(2), "{refused:?} in {:?}", started.elapsed()); + } + /// usvg takes from a `style` attribute only the presentation properties, which a radius isn't: /// one set there is not read, so there is nothing to look at in it (guards an update of usvg). #[test] diff --git a/docs/user-guide/cartography.md b/docs/user-guide/cartography.md index dde921b80a..f45e51d515 100644 --- a/docs/user-guide/cartography.md +++ b/docs/user-guide/cartography.md @@ -113,8 +113,9 @@ up, can take minutes. So one with more to draw than a 2048 × 2048 image isn't t one past 10,000 elements or 200,000 points of its shapes once each `` is counted where it repeats, nor one with a marker on a shape inside another marker (drawn on each of its vertices wherever it is), nor one whose style sheets and `style` attributes, or whose elements' attributes, -take more to read than a few milliseconds (a sheet of some 900 short rules, or 4,000 -attributes on one element). An arc is counted as the curves it is drawn with, more the larger its radius: +take more than some twenty milliseconds to read (a sheet of some 900 short rules, or 4,000 +attributes on one element). An arc is counted as the curves it is drawn with, more the larger +its radius: one of more than 200 curves isn't taken, nor is a circle, an ellipse or a rounded corner whose radius is in em or ex, which may come to any size. A radius in % is counted as that share of the largest size the SVG gives itself; such a radius isn't taken either when the SVG's own width or From c27da03c8d61849bf74750887a5f140833903235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 10:28:38 -0500 Subject: [PATCH 4/5] fix(render): an SVG entity that holds a tag is refused before reading, as no count sees what it expands to (#2800) --- crates/data/src/xml.rs | 2 +- crates/render/src/picture/svg.rs | 75 +++++++++++++++++++++++++------- docs/user-guide/cartography.md | 7 ++- 3 files changed, 63 insertions(+), 21 deletions(-) diff --git a/crates/data/src/xml.rs b/crates/data/src/xml.rs index e4a8600fac..8c51ef4203 100644 --- a/crates/data/src/xml.rs +++ b/crates/data/src/xml.rs @@ -232,7 +232,7 @@ fn close(prefixes: &mut HashMap<&[u8], usize>, prefix: &[u8]) { } /// Whether a DOCTYPE declares an entity whose value holds markup (a `<`). -fn entity_with_markup(decl: &[u8]) -> bool { +pub fn entity_with_markup(decl: &[u8]) -> bool { let mut at = 0; while let Some(p) = decl.get(at..).and_then(|r| r.windows(8).position(|w| w == b" Result { + // An entity of a tag expands to tags `attribute_pairs` doesn't see, once for each use (a text + // entity, as in an Illustrator file's `xmlns` values, is no way round it). + if rustgis_data::xml::entity_with_markup(text.as_bytes()) { + return Err(Refusal::NotSvg); + } // Before roxmltree checks each attribute of a tag against those before it. if attribute_pairs(text) > ATTRIBUTE_PAIRS { return Err(Refusal::TooMuchToRead); @@ -352,20 +358,28 @@ impl simplecss::Element for Stepped<'_, '_> { /// declarations (the `;` and `}` that end them, more than they are, never fewer) times its length, /// all added up. fn style_units(doc: &roxmltree::Document) -> u64 { - let declarations = |text: &str| text.bytes().filter(|b| matches!(b, b';' | b'}')).count() as u64; let mut units = 0u64; for n in doc.descendants() { if n.has_tag_name("style") { let sheet = sheet_of(n); - units = units.saturating_add((declarations(&sheet) + 1).saturating_mul(sheet.len() as u64)); - } - if let Some(style) = n.attribute("style") { - units = units.saturating_add((declarations(style) + 1).saturating_mul(style.len() as u64)); + units = units.saturating_add(declarations(&sheet).saturating_mul(sheet.len() as u64)); } + units = units.saturating_add(style_attribute_units(n)); } units } +/// The declarations of CSS `text`: the `;` and `}` that end them, more than they are, never fewer. +fn declarations(text: &str) -> u64 { + text.bytes().filter(|b| matches!(b, b';' | b'}')).count() as u64 +} + +/// What reading element `n`'s `style` attribute comes to ([`style_units`]), which usvg reads again +/// for each copy a `` makes of it ([`Counted::style`]). +fn style_attribute_units(n: roxmltree::Node) -> u64 { + n.attribute("style").map_or(0, |style| (declarations(style) + 1).saturating_mul(style.len() as u64)) +} + /// What reading `text`'s tags comes to, in [`ATTRIBUTE_PAIRS`]: the square of the `=` in each piece /// of it between `<`s, added up. A `<` isn't in a tag's attributes in XML that reads (roxmltree /// stops at it before it checks them), so each tag is one piece, and an attribute is one `=` of it, @@ -433,6 +447,7 @@ fn elements( by_sheet: std::collections::HashSet::new(), deep: false, run_capped: false, + unread: false, }; let counted = match count_all(doc, &mut counter) { // Past the elements written out it is too much for itself, which is known for nothing. @@ -449,6 +464,7 @@ fn count_all<'a>(doc: &'a roxmltree::Document<'a>, counter: &mut Counter<'a, '_> let refused = |c: &Counter| match (c.deep, c.run_capped) { (true, _) => Refusal::TooNested, (_, true) => Refusal::PastRun, + _ if c.unread => Refusal::TooMuchToRead, _ => Refusal::TooMuch, }; let all = counter.count(doc.root_element(), 0).ok_or_else(|| refused(counter))?; @@ -486,6 +502,9 @@ struct Counted { /// The steps matching the style sheets to it and what's under it takes ([`css_steps`]), each /// ``'s copy again: usvg reads what a `` repeats again for each, rules and all. steps: u64, + /// What reading the `style` attributes of it and what's under it comes to + /// ([`style_attribute_units`]), each ``'s copy again, as for `steps` (#2800). + style: u64, } /// [`elements`]'s count of a document. @@ -510,6 +529,8 @@ struct Counter<'a, 's> { deep: bool, /// Whether matching stopped at `cap`, below [`CSS_STEPS`] ([`Refusal::PastRun`]). run_capped: bool, + /// Whether a count stopped for `style` attributes past [`STYLE_UNITS`] ([`Refusal::TooMuchToRead`]). + unread: bool, } impl<'a> Counter<'a, '_> { @@ -550,7 +571,8 @@ impl<'a> Counter<'a, '_> { if sets { self.by_sheet.insert(n.id()); } - let mut total = Counted { elements: 1, points: points_of(n, self.viewport), marked: 0, height: 0, steps }; + let mut total = + Counted { elements: 1, points: points_of(n, self.viewport), marked: 0, height: 0, steps, style: style_attribute_units(n) }; for under in n.children().filter(|c| c.is_element()).chain(used) { let c = self.count(under, depth + 1)?; total.elements = total.elements.saturating_add(c.elements); @@ -558,6 +580,11 @@ impl<'a> Counter<'a, '_> { total.marked = total.marked.saturating_add(c.marked); total.height = total.height.max(c.height + 1); total.steps = total.steps.saturating_add(c.steps); + total.style = total.style.saturating_add(c.style); + if total.style > STYLE_UNITS { + self.unread = true; + return None; + } if total.elements > ELEMENTS || total.steps > self.cap { // Past the elements it is too much for itself, which is known for nothing. self.run_capped = total.elements <= ELEMENTS && self.cap < CSS_STEPS; @@ -1447,6 +1474,21 @@ mod tests { assert_eq!(read(&svg(&format!("{rect}", rules(edge)))).err(), Some(Refusal::TooMuchToRead)); } + /// usvg reads again what a `` repeats, its `style` attributes too, so the bound counts + /// each copy (#2800: a `` of 1,000 declarations used 3,000 times took 11 s). + #[test] + fn a_style_a_use_repeats_is_read_as_often_as_it_is_repeated() { + let uses = |n: usize| (0..n).map(|_| r##""##).collect::(); + let group = |n: usize| { + format!(r##"{}"##, "fill: red; ".repeat(1000), uses(n)) + }; + let started = std::time::Instant::now(); + assert_eq!(read(&svg(&group(3000))).err(), Some(Refusal::TooMuchToRead), "in {:?}", started.elapsed()); + // An icon's own: a few declarations on a group, used a hundred times. + let icon = format!(r##"{}"##, uses(100)); + assert!(read(&svg(&icon)).is_ok()); + } + /// An element's attributes are read within a bound before roxmltree reads them, which checks /// each of its attributes against all those before it (#2800). #[test] @@ -1464,20 +1506,20 @@ mod tests { assert_eq!(read(&svg(&format!(r#""#, attributes(100)))).err(), Some(Refusal::NotSvg)); } - /// An entity can't expand to a tag (roxmltree refuses it), so the tags counted before reading are - /// the tags read (#2800): the way round the attribute bound the text count would leave (guards an - /// update of roxmltree). + /// An entity of a tag expands, once for each use, to tags whose attributes roxmltree checks each + /// against those before it, while the text count sees its declaration once: refused before + /// reading (#2800, it took 7 s), while an entity of text, as an Illustrator file has, is read. #[test] fn an_entity_of_a_tag_with_many_attributes_is_not_a_way_round_the_bound() { - let attributes = (0..2000).map(|i| format!(r#" a{i}="1""#)).collect::(); + // In single quotes: the entity's own literal is in double ones. + let attributes = (0..2000).map(|i| format!(" a{i}='1'")).collect::(); let uses = "&t;".repeat(3000); let text = format!( r#"">]>{uses}"# ); - let started = std::time::Instant::now(); - let refused = read(&text).err(); - assert_eq!(refused, Some(Refusal::NotSvg), "read whole in {:?}", started.elapsed()); - assert!(started.elapsed() < std::time::Duration::from_secs(2), "{refused:?} in {:?}", started.elapsed()); + assert_eq!(read(&text).err(), Some(Refusal::NotSvg)); + let of_text = r#"]>"#; + assert!(read(of_text).is_ok(), "an entity of text is read"); } /// usvg takes from a `style` attribute only the presentation properties, which a radius isn't: @@ -1513,6 +1555,7 @@ mod tests { by_sheet, deep: false, run_capped: false, + unread: false, }; assert!(counter.count(doc.root_element(), 0).is_none()); assert!(counter.matched <= CSS_STEPS + 1, "{} steps", counter.matched); diff --git a/docs/user-guide/cartography.md b/docs/user-guide/cartography.md index f45e51d515..d00f2b5d55 100644 --- a/docs/user-guide/cartography.md +++ b/docs/user-guide/cartography.md @@ -114,10 +114,9 @@ one past 10,000 elements or 200,000 points of its shapes once each `` is co repeats, nor one with a marker on a shape inside another marker (drawn on each of its vertices wherever it is), nor one whose style sheets and `style` attributes, or whose elements' attributes, take more than some twenty milliseconds to read (a sheet of some 900 short rules, or 4,000 -attributes on one element). An arc is counted as the curves it is drawn with, more the larger -its radius: -one of more than 200 curves isn't taken, nor is a circle, an ellipse or a rounded corner whose -radius is in em or ex, which may come to any size. A radius in % is counted as that share of the +attributes on one element; a `style` a `` repeats counts each time). An arc is counted as the +curves it is drawn with, more the larger its radius: one of more than 200 curves isn't taken, nor +is a circle, an ellipse or a rounded corner whose radius is in em or ex, which may come to any size. A radius in % is counted as that share of the largest size the SVG gives itself; such a radius isn't taken either when the SVG's own width or height is in em or ex and it has no `viewBox`, or when the width or height of a `` or `` inside it, or of an `` inside it with no `viewBox`, is in em or ex or past 100%. An From 6a96c8490cfd6de0475212d0b72716eb81bede92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Thu, 26 Nov 2026 11:00:15 -0500 Subject: [PATCH 5/5] fix(render): an SVG entity of a tag is refused as too much to read, and style sheets count with the styles a use repeats (#2800) --- crates/engine/src/project.rs | 2 +- crates/engine/src/tests.rs | 2 +- crates/render/src/picture.rs | 5 ++-- crates/render/src/picture/svg.rs | 45 +++++++++++++++++++++++--------- crates/ui-egui/src/markerpick.rs | 2 +- docs/user-guide/cartography.md | 7 ++--- 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 971b16fe34..d55f40fe90 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -2325,7 +2325,7 @@ pub(crate) fn picture_notices_by<'a>( for (names, what) in [ ( too_much_to_read, - "Image markers in {names} are SVGs whose style sheets or element attributes take more to read than RustGIS allows and are drawn as circles", + "Image markers in {names} are SVGs whose style sheets, element attributes or entities holding tags take more to read than RustGIS allows and are drawn as circles", ), ( too_nested, diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index f7f32e90d3..fe44a0bc11 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -2749,7 +2749,7 @@ fn svg_image_markers_that_dont_draw_are_said_with_why() { (MarkerRefusal::TooManyBytes, "Image markers in \"Cities\", \"Rivers\" are longer than 2 MiB as base64 and are drawn as circles"), ( MarkerRefusal::SvgTooMuchToRead, - "Image markers in \"Cities\", \"Rivers\" are SVGs whose style sheets or element attributes take more to read than RustGIS allows and are drawn as circles", + "Image markers in \"Cities\", \"Rivers\" are SVGs whose style sheets, element attributes or entities holding tags take more to read than RustGIS allows and are drawn as circles", ), ( MarkerRefusal::SvgTooNested, diff --git a/crates/render/src/picture.rs b/crates/render/src/picture.rs index 9b2486159b..6bf4648622 100644 --- a/crates/render/src/picture.rs +++ b/crates/render/src/picture.rs @@ -82,7 +82,8 @@ pub enum MarkerRefusal { /// count, `svg::work`), or more elements than `svg::ELEMENTS` (10,000). TooMuchToDraw, /// It is an SVG whose style sheets and `style` attributes, or whose elements' attributes, take - /// more to read than `svg::STYLE_UNITS` and `svg::ATTRIBUTE_PAIRS` allow. + /// more to read than `svg::STYLE_UNITS` and `svg::ATTRIBUTE_PAIRS` allow, or whose entities + /// hold tags, which no count sees. SvgTooMuchToRead, /// It is an SVG with more XML nodes than `svg::XML_NODES` (40,000) or nested deeper than /// `svg::DEPTH` (64). @@ -139,7 +140,7 @@ refusal_phrases! { TooManyBytes => "is longer than 2 MiB as base64", TooManyPixels => "has more pixels than 2048 × 2048", TooMuchToDraw => "is an SVG with more to draw than a 2048 × 2048 image", - SvgTooMuchToRead => "is an SVG whose style sheets or element attributes take more to read than RustGIS allows", + SvgTooMuchToRead => "is an SVG whose style sheets, element attributes or entities holding tags take more to read than RustGIS allows", SvgTooNested => "is an SVG with more than 40,000 XML nodes or nested deeper than 64 levels", SvgUnknownRadius => "is an SVG with a radius whose size RustGIS can't know (in em or ex, or in % of a size in em or ex, or of a nested size in % over 100%)", SvgTooSmall => "is an SVG too small to draw", diff --git a/crates/render/src/picture/svg.rs b/crates/render/src/picture/svg.rs index 1312bd9f70..196bc5525b 100644 --- a/crates/render/src/picture/svg.rs +++ b/crates/render/src/picture/svg.rs @@ -32,8 +32,9 @@ pub(super) enum Refusal { NotSvg, /// It has more to draw than the cap given, or more elements than [`ELEMENTS`]. TooMuch, - /// Its style sheets and `style` attributes come to more than [`STYLE_UNITS`], or the attributes - /// of its elements to more than [`ATTRIBUTE_PAIRS`]: more to read than the readers do in time. + /// Its style sheets and `style` attributes come to more than [`STYLE_UNITS`], the attributes + /// of its elements to more than [`ATTRIBUTE_PAIRS`], or an entity of it holds a tag, whose + /// expansion no count sees: more to read than the readers do in time. TooMuchToRead, /// It has more XML nodes than [`XML_NODES`], or nests deeper than [`DEPTH`]. TooNested, @@ -108,7 +109,7 @@ pub(super) fn read(text: &str, cap: u64, matched: &mut u64) -> Result ATTRIBUTE_PAIRS { @@ -358,15 +359,18 @@ impl simplecss::Element for Stepped<'_, '_> { /// declarations (the `;` and `}` that end them, more than they are, never fewer) times its length, /// all added up. fn style_units(doc: &roxmltree::Document) -> u64 { - let mut units = 0u64; - for n in doc.descendants() { - if n.has_tag_name("style") { + doc.descendants().map(style_attribute_units).fold(sheet_units(doc), u64::saturating_add) +} + +/// What reading `doc`'s style sheets comes to, in [`STYLE_UNITS`]. +fn sheet_units(doc: &roxmltree::Document) -> u64 { + doc.descendants() + .filter(|n| n.has_tag_name("style")) + .map(|n| { let sheet = sheet_of(n); - units = units.saturating_add(declarations(&sheet).saturating_mul(sheet.len() as u64)); - } - units = units.saturating_add(style_attribute_units(n)); - } - units + (declarations(&sheet) + 1).saturating_mul(sheet.len() as u64) + }) + .fold(0, u64::saturating_add) } /// The declarations of CSS `text`: the `;` and `}` that end them, more than they are, never fewer. @@ -448,6 +452,7 @@ fn elements( deep: false, run_capped: false, unread: false, + sheet_units: sheet_units(doc), }; let counted = match count_all(doc, &mut counter) { // Past the elements written out it is too much for itself, which is known for nothing. @@ -531,6 +536,8 @@ struct Counter<'a, 's> { run_capped: bool, /// Whether a count stopped for `style` attributes past [`STYLE_UNITS`] ([`Refusal::TooMuchToRead`]). unread: bool, + /// What the style sheets come to ([`sheet_units`]), which the copies' `style`s add to. + sheet_units: u64, } impl<'a> Counter<'a, '_> { @@ -581,7 +588,7 @@ impl<'a> Counter<'a, '_> { total.height = total.height.max(c.height + 1); total.steps = total.steps.saturating_add(c.steps); total.style = total.style.saturating_add(c.style); - if total.style > STYLE_UNITS { + if total.style.saturating_add(self.sheet_units) > STYLE_UNITS { self.unread = true; return None; } @@ -1484,6 +1491,17 @@ mod tests { }; let started = std::time::Instant::now(); assert_eq!(read(&svg(&group(3000))).err(), Some(Refusal::TooMuchToRead), "in {:?}", started.elapsed()); + // The sheets and the copies' `style`s are one bound: each under it, together past it. + let sheet = "rect{fill:red}".repeat(600); + let both = |n: usize| { + format!( + r##"{}"##, + "fill:red;".repeat(300), + uses(n) + ) + }; + assert!(read(&svg(&both(1))).is_ok()); + assert_eq!(read(&svg(&both(18))).err(), Some(Refusal::TooMuchToRead)); // An icon's own: a few declarations on a group, used a hundred times. let icon = format!(r##"{}"##, uses(100)); assert!(read(&svg(&icon)).is_ok()); @@ -1517,7 +1535,7 @@ mod tests { let text = format!( r#"">]>{uses}"# ); - assert_eq!(read(&text).err(), Some(Refusal::NotSvg)); + assert_eq!(read(&text).err(), Some(Refusal::TooMuchToRead)); let of_text = r#"]>"#; assert!(read(of_text).is_ok(), "an entity of text is read"); } @@ -1556,6 +1574,7 @@ mod tests { deep: false, run_capped: false, unread: false, + sheet_units: 0, }; assert!(counter.count(doc.root_element(), 0).is_none()); assert!(counter.matched <= CSS_STEPS + 1, "{} steps", counter.matched); diff --git a/crates/ui-egui/src/markerpick.rs b/crates/ui-egui/src/markerpick.rs index fdcc54b742..a507be43f4 100644 --- a/crates/ui-egui/src/markerpick.rs +++ b/crates/ui-egui/src/markerpick.rs @@ -95,7 +95,7 @@ impl MarkerImage { &[("mib", &(rustgis_engine::map::symbology::MAX_PICTURE_BYTES >> 20).to_string())], ), MarkerRefusal::SvgTooMuchToRead => tl!( - "This image can't be a marker: it is an SVG whose style sheets or element attributes take more to read than RustGIS allows" + "This image can't be a marker: it is an SVG whose style sheets, element attributes or entities holding tags take more to read than RustGIS allows" ) .to_string(), MarkerRefusal::SvgTooNested => tl!( diff --git a/docs/user-guide/cartography.md b/docs/user-guide/cartography.md index d00f2b5d55..7faeca1cf6 100644 --- a/docs/user-guide/cartography.md +++ b/docs/user-guide/cartography.md @@ -114,9 +114,10 @@ one past 10,000 elements or 200,000 points of its shapes once each `` is co repeats, nor one with a marker on a shape inside another marker (drawn on each of its vertices wherever it is), nor one whose style sheets and `style` attributes, or whose elements' attributes, take more than some twenty milliseconds to read (a sheet of some 900 short rules, or 4,000 -attributes on one element; a `style` a `` repeats counts each time). An arc is counted as the -curves it is drawn with, more the larger its radius: one of more than 200 curves isn't taken, nor -is a circle, an ellipse or a rounded corner whose radius is in em or ex, which may come to any size. A radius in % is counted as that share of the +attributes on one element; a `style` a `` repeats counts each time) or that declares an entity +holding a tag. An arc is counted as the curves it is drawn with, more the larger its radius: one of +more than 200 curves isn't taken, nor is a circle, an ellipse or a rounded corner whose radius is +in em or ex, which may come to any size. A radius in % is counted as that share of the largest size the SVG gives itself; such a radius isn't taken either when the SVG's own width or height is in em or ex and it has no `viewBox`, or when the width or height of a `` or `` inside it, or of an `` inside it with no `viewBox`, is in em or ex or past 100%. An