Repository navigation
fix(image,markdown): untrusted SVG and Markdown stay within Rune's image limits and stack - #1608
Merged
Merged
Conversation
…age limits and stack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #587
Untrusted Markdown and SVG now stay inside the image limits Rune already has (
MAX_SIDE= 8192 px,MAX_ALLOC= 256 MiB incrates/rune-image/src/lib.rs), and inside the stack.What was wrong, and what changed
crates/rune/src/runtime/commit/flatten.rsrecursed once for each element with no stack check, so 2,000 nested>overflowed a 2 MiB threadflatten_owned/flatten_refrun insiderune_taffy::maybe_grow, the same stack continuation layout uses already (it does nothing on wasm)MAX_TABLE_COLUMNS). Cells past column 128 are dropped, as GFM drops cells past the headerusvg::decompress_svgzreads to the end and checks the size only afterwardscrates/rune-image/src/gzip.rs: a gzip/DEFLATE decoder that stops at 32 MiB, never reserves past that limit, and checks the CRC. It adds no dependencysvg_rgbaclampedpxonly when it was0, so a 20000wurl_setentry asked for a 20000 px pixmappxis clamped to 4096. Beforeresvg::render, a walk of the resolved tree enforcesMAX_SIDEon each pattern tile and isolated layer, andMAX_ALLOCon the total of canvas, tiles, layers, masks, clips, nested SVGs and embedded images. It also enforces a limit of 100,000 nodes<use>fan-out<use>before anything can countTree::from_xmltreeresolve_stringresolver already returnedNone(#1188). The data resolver did not check raster headers, andImageCache::file/url/font_filecalledstd::fs::readon any pathdata:rasters go throughheader::check(the #1559 limits). File loads go throughread_regular_file, which refuses anything that is not a regular file (directories, FIFOs, sockets, devices) before and after open, and stops reading atMAX_ALLOCThe SVG code moves out of
lib.rsintocrates/rune-image/src/svg.rs. The publicsvg_rgbaandsvg_rgba_coverkeep their signatures.Refused by default
<image>or<feImage>href that is not adata:URL, which includes files beside the SVG, absolute paths and UNC paths. No opt-in is added: if an app needs SVGs that reference files beside them, that is the owner's decision.data:URLs of typeimage/svg+xml(nested SVG documents), as before.Not fixed here
Tests
All hostile inputs are built inside the tests. The SVGZ bomb is about 420 KiB of fixed-Huffman deflate that would inflate to 65 MiB. The tests create no FIFO or device file. The path check is tested with a directory and, on Windows,
\\.\NUL.crates/rune-image/src/svg_tests.rs:url_setentrydata:PNG headers of 100,000 px andu32::MAX<use>fan-outcrates/rune-kit/src/markdown/tests.rs: a 500-column table and a pending table header are capped at 128 columns, and 2,000 nested quotes, deep lists and nine-digit lists render a frame. Before this fix the table kept 500 columns and the quotes overflowed the stack.