Repository navigation
Done
Description
What
#2704 (part E1a of #2266) bounds SVG marker images before they are read and drawn. Its review raised bounds that can be tighter against crafted SVGs, and refusal phrases that name the wrong cause. They were left out of that PR to keep it to its behaviour, and are collected here.
Bounds on reading (crates/render/src/picture/svg.rs)
- Style sheets on many elements. The reader tries each rule of a
<style>on each element (usvg'sparse_svg_element), so a large sheet on many elements takes as long as both. Nothing bounds that product today. - Marker points on every vertex. Each marker's elements count on every vertex it can sit on, but its points don't. A long path inside a marker on a shape of many vertices passes the point cap.
- Markers counted where they are used. Today every
<marker>counts on every vertex of the document, referenced or not. An icon with an unused marker and about 5,000 points is refused. Counting only markers a shape names (marker-start,marker-mid,marker-end), on that shape's points, is both tighter and fairer. - Gradient stops. tiny-skia goes through all of a gradient's stops at every pixel, but the cost counts a gradient the same whatever its stops.
- One arc's curves. An arc may come to 1,000 cubic curves. svgtypes moves each across all those still to go, which is quadratic, so a lower cap (about 200) bounds reading more tightly.
- Polyline numbers.
points_ofsplits a polyline on non-digits, so12.345,67.891counts four runs and a polyline about twice its points. The doc's example (1e5one number) is wrong too. Count numbers as svgtypes reads them. - Plain rectangles. A
<rect>without rounded corners counts 0 points; usvg reads it as 5. - Radii in %. A radius in %, em or ex is refused, as it may resolve to any size. A % radius could be resolved against the root view box and counted at that size.
- CSS escapes.
@\69mportor\75rl(in a style sheet isn't matched by the@importandurl(checks. The reader never fetches an import, and simplecss 0.2.2 doesn't decode escapes, so catching them means decoding the sheet first.
Refusal phrases (crates/render/src/picture.rs)
- The 1.5 MiB byte cap, the XML node and depth limits, and a radius in %, em or ex all say "is an SVG with more to draw than a 2048 × 2048 image".
- An SVG too small to scale, one that isn't drawn, and one that isn't UTF-8 say it "isn't a PNG, JPEG or SVG RustGIS reads".
Each should say its own cause.
Related
- Picture markers take SVG images, bounded in reading and drawing (#2266 part E1a) #2704 (review threads on
svg.rs:203andpicture.rs:300) - [Feature]: Picture markers: a PNG, JPEG or SVG image as a point's marker #2266
Metadata
Metadata
Assignees
Labels
No labels
Activity
jgregoriorincon commentedon Nov 22, 2026
More from the review of #2704 (rounds 3 to 5):
verticesinelements), an unused marker's too; rename the binding and its comment's wording along with counting a marker only where a shape names it;svg::draw; checked by hand on d6cacc7, no panic;%,emorexis refused instead of taken as zero;<use>'shrefis trimmed inundrawnbut not incount;store()'s "80 ms" under the lock leaves out SVG reading and drawing;cartography.md's "(more where it says it is larger)" reads as past 700 px; wraps insvg.rs's module andundrawndocs and incartography.md.jgregoriorincon commentedon Nov 22, 2026
From round 6 of #2704:
cartography.md:100says an SVG given by command is "of at most 2048 × 2048 pixels", which holds for PNG and JPEG only;svg.rs:21"animation (the still image is drawn)" reads as if animation were drawn;elsewherelowercases every attribute value to search it, a copy of up to 1.5 MiB; the wall-clock bounds (under 1 s) in the SVG tests; the picker's unreadable-image notice names PNG and JPEG only (part E1b).jgregoriorincon commentedon Nov 22, 2026
From round 7 of #2704: the
points_ofcomment's sentence about a polyline's runs of digits is garbled; long lines incartography.mdandworkspace.md; the testa_marker_is_a_png_or_a_jpegand its comment predate SVG;MarkerRefusal's public docs link privatesvgitems (private_intra_doc_links); with two markers, a style sheet styling only a class like.marker-dotis refused, as any sheet naming markers is.jgregoriorincon commentedon Nov 23, 2026
From the last review of #2704:
countreuses a subtree it memoized at a shallow depth when a<use>reaches it deeper, without checking its depth again, so usvg's ownmax_depthrefuses such an SVG, said with "isn't a PNG, JPEG or SVG" rather than "more to draw".jgregoriorincon commentedon Nov 23, 2026
I'll take this, in two PRs: (1) the reading bounds in
crates/render/src/picture/svg.rs(markers counted only where a shape names them, style sheets × elements, gradient stops, a lower arc cap, polyline numbers, quadratic points,%radii against the view box and zero radii, the memoized depth); (2) the refusal phrases, one per cause, with the doc wording points from the comments. CSS escapes need no change: nothing is fetched and simplecss doesn't decode them.docs(render): give the SVG marker arc and % radius bounds in the user…
fix(render): count SVG marker images more tightly and fairly before r…
fix(render): say each SVG marker image refusal's own cause (opengeos#…
docs(cartography): say which sizes make an SVG's % radius unknown (op…
fix(render): say an SVG marker image's unknown % radius and past-dept…