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
Native AVIF: enforce the pixel budget in rav1d and before RGBA conversion #1719
Could Rune enforce its native AVIF pixel budget in the decoder as well as in preflight?
#1516 added container and AV1 header checks for #888. Current dev still uses avif-decode 3.0.0, whose rav1d wrapper leaves Dav1dSettings::frame_size_limit at its default. In crates/rune-image/src/avif.rs, Rune also collects the RGBA buffer before checking the dimensions returned by the decoder.
Please keep preflight, enforce the frame budget in the codec, and check returned dimensions and checked RGBA byte size before allocating the conversion buffer. A decoder-side limit would also let callers with smaller preview surfaces enforce their own pixel budget.
The post-decode RGBA conversion hardening is now merged on dev in #1891 (bbaf6c8ab):
What landed: crates/rune-image/src/avif.rs now validates decoded dimensions and checked RGBA8 byte size (w * h * 4) against Rune's shared raster limits (MAX_SIDE = 8192, MAX_ALLOC = 256 MiB, matching image::Limits in crates/rune-image/src/lib.rs) before allocating any conversion buffer, and pre-allocates exact capacity with Vec::try_reserve_exact across all six avif_decode::Image variants. Preflight check_limits and public ImageCache APIs are unchanged.
Verified: cargo test -p rune-image --features avif on macOS arm64 (60 passed, 2 ignored), cargo check -p rune-image --features avif --tests on Linux aarch64, and cargo test -p rune-image (57 passed, 2 ignored), rune image/texture-limit/integration tests, and wasm32 checks on Windows x86_64.
Not run: --features avif on Windows x86_64 (requires NASM for rav1d x86 assembly), and no live window (internal decoder hardening only).
Leaving this issue open for the two remaining parts:
Enforcing Dav1dSettings::frame_size_limit inside rav1d (avif-decode 3.0.0 leaves it at 0 and exposes no setter, so this requires vendoring/patching avif-decode or replacing it with direct avif-parse/rav1d/yuv dependencies).
Caller-configurable per-load pixel budgets for smaller preview surfaces.
Thanks for the detailed write-up! Part of this is already on dev. #1891 (bbaf6c8a) changed crates/rune-image/src/avif.rs so that it checks the decoded dimensions and the RGBA8 byte size (w * h * 4, overflow-checked, against MAX_SIDE/MAX_ALLOC), then reserves the conversion buffer with try_reserve_exact before converting. The preflight in limits::inspect is unchanged.
Two parts are still open, and this issue now tracks them:
Codec-side limit:rgba() calls avif_decode::Decoder::from_avif(..).to_image() without passing any decoder settings. As noted above, avif-decode 3.0.0 has no way to set Dav1dSettings::frame_size_limit. Setting it means patching or vendoring avif-decode, or calling avif-parse and rav1d directly.
Caller-supplied budget: an optional per-load pixel budget below the global limit, for callers that only show small previews.
I looked into the codec-side limit and haven't opened a change for it yet. On docs.rs, avif-decode 3.0.0's Decoder::from_reader creates its rav1d decoder with only a thread count, and its public API has no way to set Dav1dSettings::frame_size_limit. Setting it means either vendoring avif-decode with a patch, following the repo's other vendor/* crates, or replacing it with direct avif-parse/rav1d/yuv calls. Either way it's a decoder change that has to be built and tested against real AVIF files with --features avif, and I couldn't do that this time.
Until then, native AVIF still goes through the container and AV1 header preflight (#1516) and the post-decode dimension and byte-budget checks before the RGBA allocation (#1891). This issue stays open for the in-codec limit and for a caller-supplied per-load pixel budget.
Both remaining parts are now merged on dev in #2641 (70f7a5553):
Codec-side rav1d pixel budget: Replaced the avif-decode 3.0.0 wrapper with direct avif-parse, pure-Rust rav1d, and yuv decoding in crates/rune-image/src/avif/codec.rs. Dav1dSettings::frame_size_limit is now set to the caller's effective pixel budget (with zero-pixel budgets rejected before opening rav1d, since 0 disables the limit in rav1d) so oversized primary and alpha frames fail with ERANGE before frame-plane allocation. Decoded dimensions, pixel count, and checked RGBA8 byte size are validated before calling Vec::try_reserve_exact, converting straight into the final RGBA8 buffer with no intermediate full-frame RGB/RGBA16 allocation.
Per-load caller pixel budget: Added ImageLimits (with_max_side, with_max_pixels, with_max_alloc, clamped to Rune's global 8192 px / 67,108,864 px / 256 MiB ceiling) with ImageCache::load_with_limits and ImageCache::load_scaled_with_limits (re-exported as rune::ImageLimits). Default limits share cache entries with load/load_scaled; tighter limits use separate cache keys and are enforced across native AVIF, still rasters, animated GIF/WebP/APNG, SVG, and web header preflight (header::check_with_limits).
Verified locally (Windows x86_64): cargo test -p rune-image --features avif (106 passed, 2 ignored; 12 doc-tests passed, including direct rav1dframe_size_limit rejection bypassing preflight on hello-320.avif, real AV1 alpha-plane decoding, and ImageCache::load_with_limits tests), cargo test -p rune-image (102 passed, 2 ignored), cargo check -p rune-image --no-default-features, cargo check -p rune --features avif, cargo check -p rune-image --target wasm32-unknown-unknown (default and --no-default-features), and scripts/file-size.sh.
Not run on real hardware: macOS, Linux, and live browser runtimes were not exercised directly.
Closing as completed — please reopen if anything is still off.
Activity
Hona commentedon Nov 24, 2026
The post-decode RGBA conversion hardening is now merged on
devin #1891 (bbaf6c8ab):crates/rune-image/src/avif.rsnow validates decoded dimensions and checked RGBA8 byte size (w * h * 4) against Rune's shared raster limits (MAX_SIDE = 8192,MAX_ALLOC = 256 MiB, matchingimage::Limitsincrates/rune-image/src/lib.rs) before allocating any conversion buffer, and pre-allocates exact capacity withVec::try_reserve_exactacross all sixavif_decode::Imagevariants. Preflightcheck_limitsand publicImageCacheAPIs are unchanged.cargo test -p rune-image --features avifon macOS arm64 (60 passed, 2 ignored),cargo check -p rune-image --features avif --testson Linux aarch64, andcargo test -p rune-image(57 passed, 2 ignored),runeimage/texture-limit/integration tests, andwasm32checks on Windows x86_64.--features avifon Windows x86_64 (requires NASM forrav1dx86 assembly), and no live window (internal decoder hardening only).Leaving this issue open for the two remaining parts:
Dav1dSettings::frame_size_limitinsiderav1d(avif-decode3.0.0 leaves it at0and exposes no setter, so this requires vendoring/patchingavif-decodeor replacing it with directavif-parse/rav1d/yuvdependencies).opencodejr commentedon Nov 25, 2026
Thanks for the detailed write-up! Part of this is already on
dev. #1891 (bbaf6c8a) changedcrates/rune-image/src/avif.rsso that it checks the decoded dimensions and the RGBA8 byte size (w * h * 4, overflow-checked, againstMAX_SIDE/MAX_ALLOC), then reserves the conversion buffer withtry_reserve_exactbefore converting. The preflight inlimits::inspectis unchanged.Two parts are still open, and this issue now tracks them:
rgba()callsavif_decode::Decoder::from_avif(..).to_image()without passing any decoder settings. As noted above,avif-decode3.0.0 has no way to setDav1dSettings::frame_size_limit. Setting it means patching or vendoringavif-decode, or callingavif-parseandrav1ddirectly.opencodejr commentedon Nov 25, 2026
I looked into the codec-side limit and haven't opened a change for it yet. On docs.rs,
avif-decode3.0.0'sDecoder::from_readercreates its rav1d decoder with only a thread count, and its public API has no way to setDav1dSettings::frame_size_limit. Setting it means either vendoringavif-decodewith a patch, following the repo's othervendor/*crates, or replacing it with directavif-parse/rav1d/yuvcalls. Either way it's a decoder change that has to be built and tested against real AVIF files with--features avif, and I couldn't do that this time.Until then, native AVIF still goes through the container and AV1 header preflight (#1516) and the post-decode dimension and byte-budget checks before the RGBA allocation (#1891). This issue stays open for the in-codec limit and for a caller-supplied per-load pixel budget.
Hona commentedon Nov 27, 2026
Both remaining parts are now merged on
devin #2641 (70f7a5553):rav1dpixel budget: Replaced theavif-decode3.0.0 wrapper with directavif-parse, pure-Rustrav1d, andyuvdecoding incrates/rune-image/src/avif/codec.rs.Dav1dSettings::frame_size_limitis now set to the caller's effective pixel budget (with zero-pixel budgets rejected before openingrav1d, since0disables the limit inrav1d) so oversized primary and alpha frames fail withERANGEbefore frame-plane allocation. Decoded dimensions, pixel count, and checked RGBA8 byte size are validated before callingVec::try_reserve_exact, converting straight into the final RGBA8 buffer with no intermediate full-frame RGB/RGBA16 allocation.ImageLimits(with_max_side,with_max_pixels,with_max_alloc, clamped to Rune's global 8192 px / 67,108,864 px / 256 MiB ceiling) withImageCache::load_with_limitsandImageCache::load_scaled_with_limits(re-exported asrune::ImageLimits). Default limits share cache entries withload/load_scaled; tighter limits use separate cache keys and are enforced across native AVIF, still rasters, animated GIF/WebP/APNG, SVG, and web header preflight (header::check_with_limits).cargo test -p rune-image --features avif(106 passed, 2 ignored; 12 doc-tests passed, including directrav1dframe_size_limitrejection bypassing preflight onhello-320.avif, real AV1 alpha-plane decoding, andImageCache::load_with_limitstests),cargo test -p rune-image(102 passed, 2 ignored),cargo check -p rune-image --no-default-features,cargo check -p rune --features avif,cargo check -p rune-image --target wasm32-unknown-unknown(default and--no-default-features), andscripts/file-size.sh.Closing as completed — please reopen if anything is still off.
fix(rune-image): enforce AVIF pixel budget in rav1d and add per-load …