Repository navigation
Description
Markdown from a model or a chat message, and an SVG from a web response, can abort the app or read the user's files. catch_unwind can't stop any of these.
1. Markdown: unbounded nesting overflows the stack
The parser keeps every open quote, list and item with no limit. The renderer, the plain-text and block-map walks, and the block tree's own drop all recurse a level or more for each nesting. So a reply of 100,000 nested > or - overflows the main thread's stack and aborts the app. That's a few hundred KB, which a broken or hostile model can send.
The parser has two other gaps:
- Tables have no column limit: a 10,000-column table lays out every column, and takes 10.9 s.
- A list item's copied indent (
Flow::cols, au8) overflows at 24 levels of nine-digit numbered lists. That is a panic in debug builds.
2. SVG: local files, a FIFO, and unbounded expansion
svg_rgba parses with usvg::Options::default():
- Local files. usvg's href resolver reads any existing path in an
<image href>. So an SVG can draw the user's local files into the app, and an href naming a FIFO blocks the decode thread inopen()for good. - SVGZ. usvg inflates SVGZ to the end, with no cap.
- Reference cycles. usvg 0.45's cycle check (
fix_recursive_links) catches only cycles of one or two steps. Three clip paths in a ring recurse until the decode thread's 2 MiB stack overflows, and the app aborts. - Nesting. A thousand nested
<svg>overflow roxmltree the same way. - Expansion.
<use>fan-out, mask fan-out and per-vertex markers build millions of nodes inside usvg before anything can count them. - Raster size. resvg draws a pattern's tile at its own size, so a 20,000 px tile in an 8 px SVG asks for a 1.6 GB pixmap. The 4096 px clamp applies only to
px == 0, so aurl_setsource listed at 20000w asks for a 20000 px pixmap.
Fix
Three commits on dev 14e3c5d, on branch safety-hostile-content of Entrpi/rune.
a1d5a017: move only. SpanMap and BlockMap move unchanged from markdown/parser.rs into markdown/map.rs, so the next commit keeps the parser under 800 lines.
c67d901e: Markdown caps, in markdown/limits.rs. The builder applies them, so whole documents and streams get the same parse.
- Depth. A quote or list opened past 32 levels is not pushed. Its blocks go to the innermost open container, so the text stays, in order.
- Columns. A table keeps its first 128 columns, the way GFM drops a row's cells past its header's.
- Blocks. After 100,000 blocks, list items and table rows, the rest of the source is one paragraph of its text as written. An image that would lift into its own block counts too. The kit's largest test document (1 MB) has 28,832.
- Indent. The copied indent saturates at 255 columns.
- Timing. Release-build parse and first frame of each adversarial input take 2.4 to 9.2 ms. The tests assert a 2 s bound in debug builds.
463f9472: SVG bounds that Rune can own, in image/svg.rs.
- Images. An
<image>draws onlydata:hrefs. The opt-in isImageCache::new(waker).svg_file_images(true), and even then only a regular file is read, never a FIFO or a device. - SVGZ inflates through a 64 MiB cap.
- Nesting. A linear pass over the raw markup refuses more than 64 levels before roxmltree parses it. Entities count only when the body can reach them.
- After usvg builds the tree, a 100,000-node budget and a pixel budget apply. The pixel budget counts each image's raster, each nested SVG's canvas and each pattern tile at its drawn size, in saturating
f64. - Raster size. Every raster is clamped to 4096 px a side,
url_setwidths included.
Not fixed here: cycles and fan-outs inside usvg
A reference cycle among clip paths, masks, filters, gradients, patterns or markers is resolved inside usvg 0.45, before any Rune bound runs. Rune can't stop that without re-implementing usvg's reference resolution, and every spelling usvg accepts is another way around such a check:
- whitespace in a quoted
url(), and@import; - duplicate or SVG-namespaced IDs, and a namespaced
href; clip-path: inherit;- a
<use>that moves an element out of a clip path; - a comment that splits a
<style>.
A minimal case, which aborts the app on dev:
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8">
<clipPath id="a" clip-path="url(#b)"><rect width="8" height="8"/></clipPath>
<clipPath id="b" clip-path="url(#c)"><rect width="8" height="8"/></clipPath>
<clipPath id="c" clip-path="url(#a)"><rect width="8" height="8"/></clipPath>
<rect width="8" height="8" clip-path="url(#a)"/>
</svg>I ran 30 hostile and benign cases three ways: resvg 0.45.1, resvg git main at 500d8605a2, and this branch. Each case ran in its own process, on a 2 MiB decode thread, with a 20 s limit.
| Cases | resvg 0.45.1 | resvg main | This branch |
|---|---|---|---|
| 9 clip-path rings, however spelled | abort | draw | abort |
a two-node gradient href loop, reached through a prefix |
hang | draw | hang |
mask fan-out, marker chain, combinatorial selector, declaration fan-out, tref copies |
hang | hang | hang |
<use> fan-out to 222,222 nodes, 100,000 px and u32::MAX rasters, 20,000 px pattern tile, 1000-deep nesting |
draw or allocate | draw or allocate | refused |
| SVGZ bomb | inflates | refused | refused |
| 4 ordinary drawings | draw | draw | draw |
So:
- resvg main fixes the cycle class: Properly recognize and reject recursive references linebender/resvg#1225 adds an iterative cycle search over the resolved tree, and A one-line field's placeholder runs past the field; its typed text is cut at the box #1223 makes the parse depth configurable. Neither is released yet. Upgrading to the first release that carries them fixes the rings and the gradient loop.
- The five fan-out cases hang even on resvg main. Those need a fix in usvg.
- A marker that repeats a 1 MiB image on 1,000 vertices draws on all three decoders, at about 1 GB of memory.
Tests
-
Markdown.
markdown/limits_tests.rsparses each adversarial source, then draws a frame of it whole and one streaming. Against the previous parser:- the quote and list tests abort with a stack overflow;
- the nine-digit list test panics;
- the table test takes 10.9 s.
-
SVG.
image/svg_tests.rscovers the bounds Rune owns, on a 2 MiB decode thread, so a regression aborts the test rather than passing. The tests cover:data:images, and trusted local files;- a FIFO href, which returns at once;
- a 65 MiB SVGZ bomb;
- 1000-deep nesting, comment-hidden close tags and nesting from an entity;
- a
<use>fan-out of 222,222 nodes; - PNG headers at 100,000 px and at
u32::MAX; - a 20,000 px pattern tile;
- a 20000 px request through
url_set.
On dev's
svg_rgba, each of them draws, hangs or returnsOk. -
No false refusals. On 15,618 unique local SVGs, the branch draws every file plain usvg draws, and none takes notably longer. They are icon sets, editor and app assets, and Inkscape and Illustrator exports.
Each item has a changelog fragment.
On macOS (Apple silicon), the documented test command, cargo test -p rune -p rune-kit --features rune-kit/markdown --no-fail-fast, passes with this branch and the other three safety branches merged on dev 14e3c5d: 2,786 passed, 0 failed. Dev alone gives 2,749 passed, 0 failed. The four branches are safety-secure-fields, safety-hostile-content, safety-gpu-failures and safety-release-dev-surface; they merge cleanly except for one import line in image.rs. cargo check --workspace --all-targets and scripts/file-size.sh pass.
Filed together with #586, #588 and #589, the other safety fixes from the same review.
Activity
Hona commentedon Nov 23, 2026
Each of these is fixed on dev in #1608 (e647aa9): SVGZ inflates through a 32 MiB cap; SVG rasters and pattern tiles stay within the 8192 px and 256 MiB image limits, and any requested size is clamped to 4096 px; <use>\ fan-out and nesting hidden in entities are refused; SVG image hrefs other than \data:\ URLs stay refused; file loads refuse anything that is not a regular file; GFM tables keep 128 columns; deep Markdown no longer overflows the stack in the commit flatten. Two things remain, because they happen inside usvg 0.45: reference cycles of three or more clip paths, masks or filters, and mask or marker fan-out. They need a usvg upgrade.
Hona commentedon Nov 23, 2026
Follow-up on SVG
<image>/<feImage>references: Rune keeps external file references refused with no opt-in, matching Google Chrome and the SVG specifications for SVGs used as images.data:subresource requests inside an SVG image unconditionally (BaseFetchContext::CanRequestInternalinthird_party/blink/renderer/core/loader/base_fetch_context.ccandIsolatedSVGDocumentHost::LocalFrameClient::GetURLLoaderFactoryinthird_party/blink/renderer/core/svg/graphics/isolated_svg_document_host.cc) and loadsSVGImagewith a null base URL (third_party/blink/renderer/core/svg/graphics/svg_image.cc), so even a sibling image file next to the SVG is never loaded.#idanddata:URLs resolve; WPTcss/css-images/svg-images-are-ignored.htmlverifies this for a sibling PNG file.In Rune,
svg_optionsincrates/rune-image/src/svg.rsalready follows this rule (resolve_stringreturnsNone, andresolve_dataaccepts validated rasterdata:URLs only). Apps that need raster images inside an SVG should inline them asdata:URLs.fix(gpu): DX12 compiles with DXC when dxcompiler.dll ships beside the…