Skip to main content

Module svg

Module svg 

Source
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 * 4 bytes.

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_wrapped or empty_wrapped wrote.
looks_like_svg
Whether bytes read as an SVG document: an <svg tag near the start, past any BOM, XML declaration, comments or doctype. Only a routing hint; rasterize decides.
rasterize
Render an untrusted SVG so its longest side is max_dim pixels (capped at MAX_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 .svg path 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).