Field notes/Mediarusty_svgtreeSVGresvg

rusty_svgtree: SVG Parsing and Rendering in Safe Rust

rusty_svgtree 0.1.0 parses SVG into a simple render tree and draws it with rusty_raster. Hostile files error or clamp. Filters are missing and resvg is faster today.

Signed by M·
Painted architect unrolling a large plan of clean lines and curves across a sunlit drafting table
What is rusty_svgtree?

rusty_svgtree is a Rust SVG parser and renderer. It turns an SVG document into a simplified render tree covering paths, shapes, transforms, viewBox, CSS, gradients, use and symbol, clip paths, masks, group opacity and embedded PNG or JPEG images, then draws that tree with rusty_raster. Version 0.1.0 is on crates.io under Apache-2.0.

Ship it

Hostile SVG Errors or Clamps

instead of reaching a renderer, with drawing done by rusty_raster.

Open the rusty_svgtree conversion pin →

rusty_svgtree 0.1.0 parses SVG into a simplified render tree and draws it with rusty_raster. Hostile files return an error or get clamped instead of steering the renderer. Two limits come first, because they decide whether it fits your files today: SVG filters are not implemented, and resvg was 1.91 times faster on the 98 corpus files both libraries render identically.

SVG looks like a picture and behaves like a program. A file can nest groups thousands deep, point use elements at each other in a loop, declare a canvas a million pixels wide, or embed a giant image as base64. Anything that renders SVG from users, such as avatars, logos in a CMS or icons in a document converter, runs a parser on that input. rusty_svgtree is the house parser and renderer for that job, written so the worst case is an error.

It ships from the remade_ffmpeg_rs monorepo and is on crates.io. Pin it from the rusty_svgtree repo page.

From Markup to a Render Tree

What the parser keeps

SVG has many ways to say the same thing: shapes as elements or as paths, styles as attributes, inline CSS or style sheets, reuse through use and symbol. rusty_svgtree resolves all of that into one simplified tree of paths with their fills, strokes, transforms and clipping, the same idea as usvg. Supported input covers paths and basic shapes, transforms, viewBox, CSS, linear and radial gradients, use and symbol, clip paths, masks, group opacity, and embedded PNG and JPEG images.

Bounding hostile input

The rule for the crate is that hostile input either returns an error or is clamped to a safe value. Embedded images go through the house decoders, rusty_png and rusty_jpeg, which treat malformed data as an error too. Before trusting it with your own worst cases, feed it the files that broke your last renderer: deep nesting, use loops, absurd canvas sizes and oversized embedded images are the usual suspects, and the crate's tests and source in the monorepo show how each is handled.

Drawing the tree

Rendering is a walk over the tree that issues fills, strokes, masks and image draws to rusty_raster, the hardened tiny-skia fork released the same day. Neither crate allows unsafe code, so the path from SVG text to finished pixels is safe Rust throughout.

Where It Stands Against resvg

The 1.91x gap

resvg is the reference Rust SVG renderer, and on the 98 corpus files where both libraries produce identical output, it was 1.91 times faster than rusty_svgtree 0.1.0. That number is the honest starting point. If throughput on trusted files is your main need, resvg is the better choice today. The comparison only counts files with identical output, so it measures the same work done twice, not a shortcut taken by either side.

No filters yet

SVG filters, the effects behind blurs, drop shadows, colour matrices and lighting, are not implemented. A file that depends on them will render without the effect. Check your own corpus for filter elements before switching. Design tools often add a filter for a soft shadow even when the artwork does not need one, so a quick export setting change can bring a file back into range.

Checking your own files first

Before switching, run your real SVG set through both renderers. A short script that parses every file with rusty_svgtree, renders it, and does the same with resvg will sort your corpus into three piles: files that match, files that differ, and files that use features 0.1.0 does not have. Search the third pile for <filter, filter= and CSS filter: first, since filters are the known gap. Time the first pile on your own hardware too. The 1.91x figure comes from one corpus, and your files may land on either side of it.

Wiring it into an upload path

A typical upload handler does three things with an SVG: decide whether to accept it, render a preview, and store the original. rusty_svgtree covers the first two in one pass, because parsing is the acceptance test. If the parser returns an error, reject the upload with a clear message. If it succeeds, render the tree at your preview size with rusty_raster, encode the result with rusty_png, and store both. A file that parses but renders blank usually depends on filters or on a feature outside the supported list above, so log those for review instead of failing silently.

When to choose it anyway

Choose rusty_svgtree when the SVG comes from people you do not control and the features you need are the common ones: icons, logos, diagrams and charts. Upload pipelines, document converters such as RAG Converter, and services on MATA.NETWORK that turn user files into thumbnails are the intended homes. Its output pairs with rusty_image or rusty_icc when the result needs another format or colour space. The W3C SVG 2 specification is the reference for the features listed here.

FAQ

Quick answers for builders evaluating this technology.

What does rusty_svgtree replace?

It covers the same ground as resvg and usvg for the SVG features it supports. It does not yet implement SVG filters, so files that rely on blur, drop shadows or other filter effects still need resvg.

Is rusty_svgtree as fast as resvg?

No. On the 98 corpus files that both libraries render identically, resvg was 1.91 times faster. rusty_svgtree 0.1.0 is about safe handling of untrusted input and a small render tree, not speed parity.

What happens with a malicious SVG file?

Hostile input either returns an error or is clamped to a safe value, and embedded images are decoded by rusty_png and rusty_jpeg, which reject malformed data. Both rusty_svgtree and rusty_raster forbid unsafe code.

Which SVG features are missing in 0.1.0?

Filters are the documented gap. Paths, basic shapes, transforms, viewBox, CSS styling, gradients, use and symbol, clip paths, masks, group opacity and embedded PNG and JPEG are implemented.

How does rusty_svgtree draw the image?

It hands its render tree to rusty_raster, a fork of tiny-skia with unsafe code forbidden. Embedded raster images are decoded by the house rusty_png and rusty_jpeg crates.