Expand description
Untrusted SVG, rendered to pixels in Rust: no SVG markup reaches a webview from here.
Opened as a document, an SVG runs scripts, fetches, animates and exposes the browser engine’s
whole SVG implementation; as pixels it is only a picture. Rendering is still attackable by
resources alone, so before resvg sees a document it is parsed once, node-capped, and walked the
way rendering would expand it (<use> clones, pattern paints, marker vertices, masks, clips,
filters, offscreen layers) against fixed budgets. That same parsed document is what usvg then
converts, so the budget and the renderer can’t read two different trees. usvg reads nothing from
disk or the network: string hrefs are refused, embedded images are PNG/JPEG by their bytes and
dimension-checked from their headers, and compressed SVG is never inflated.
Structs§
- Rendered
- A rendered SVG: straight (non-premultiplied) RGBA,
width * height * 4bytes.
Constants§
- MAX_
RENDER_ DIM - Longest side a render may have.
- MAX_
SVG_ BYTES - Largest SVG accepted, in bytes.
Functions§
- empty_
wrapped - A blank wrapped SVG, for a file that refused to render: it shows nothing rather than the original.
- is_
raster_ wrapped - Whether this is an SVG
rasterize_wrappedorempty_wrappedwrote. - looks_
like_ svg - Whether bytes read as an SVG document: an
<svgtag near the start, past any BOM, XML declaration, comments or doctype. Only a routing hint;rasterizedecides. - rasterize
- Render an untrusted SVG so its longest side is
max_dimpixels (capped atMAX_RENDER_DIM). Refuses anything over budget rather than rendering part of it. - rasterize_
png rasterize, encoded as PNG.- rasterize_
wrapped rasterize, wrapped in a minimal SVG Vector writes itself: one<image>holding the rendered PNG. For a file whose.svgpath is already stored and must keep working: the webview then parses markup Vector wrote, never the sender’s.- unwrap_
raster - The PNG inside a render Vector wrapped, or None for anything else (and for an empty one).