You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AVIF: the raster is decoded before its dimensions are checked, so a small file can allocate about 1 GiB #888
An AVIF image is decoded before its size is checked, so a small file can allocate about 1 GiB
At rev 09a7590 (the avif feature), ImageCache::load hands AVIF bytes to image/avif.rs:
crates/rune/src/image/avif.rs:14 — avif_decode::Decoder::from_avif(bytes)?.to_image() decodes the whole raster and then collects it into a Vec<u8> (:16-22).
crates/rune/src/image/avif.rs:24 — if w == 0 || h == 0 || w > 8192 || h > 8192 refuses the image only after that allocation.
The other raster path is capped before it decodes: crates/rune/src/image.rs:626-634 sets max_image_width/height = 8192 and max_alloc = 256 MiB on the image reader's Limits. image.rs:624-626 (if avif::is_avif(bytes) { avif::rgba(bytes) }) returns before those limits exist, so AVIF gets none of them.
A 16,384 x 16,384 AVIF of one flat colour is a few KB on the wire (and a captured response body is hostile input: Rune draws images from arbitrary web responses). to_image() materialises roughly 1 GiB of RGBA before line 24 refuses it. The still-image decode runs on a cache worker thread (image.rs:167-176), so this is not a panic, but it is an allocation driven by untrusted input, and several such images in a view can exhaust memory.
Suggested fix: read the image's ispe dimensions first (or use rav1d's own decoder limits) and refuse anything over the same 8192 px a side, plus cap the total allocation, before decoding. ImageCache::load's doc comment (image.rs:186-192) already promises AVIF among the formats it decodes, so callers cannot tell this path apart.
This is a different gap from #587 (Markdown and SVG). The SVG side of #587 covers local files, SVGZ, nesting and raster size; AVIF is not mentioned there.
AVIF files were decoded in full before their size was checked. Rune now reads the container and AV1 headers first and refuses anything over 8192 px per side or 256 MiB of decoded pixels before decoding. Fixed on dev in #1516 (63101ea).
Activity
Hona commentedon Nov 23, 2026
AVIF files were decoded in full before their size was checked. Rune now reads the container and AV1 headers first and refuses anything over 8192 px per side or 256 MiB of decoded pixels before decoding. Fixed on dev in #1516 (63101ea).