Skip to content

fix(rune-image): enforce AVIF pixel budget in rav1d and add per-load ImageLimits - #2641

Merged
Hona merged 1 commit into
devfrom
fix/avif-rav1d-budget
Nov 27, 2026
Merged

Hona merged 1 commit into
devfrom
fix/avif-rav1d-budget

Conversation

@Hona

@Hona Hona commented Nov 27, 2026

Copy link
Copy Markdown
Member

Summary

  • Codec-side rav1d pixel budget: Replaced the avif-decode 3.0.0 wrapper (which left Dav1dSettings::frame_size_limit = 0 and allocated unchecked intermediate RGB/RGBA16 buffers) with a direct avif-parse + pure-Rust rav1d + yuv decoder in crates/rune-image/src/avif/codec.rs.
    • Sets Dav1dSettings::frame_size_limit to the caller's effective pixel budget (rejecting zero-pixel budgets before opening rav1d, since 0 disables the limit in rav1d) so oversized primary and alpha frames fail with ERANGE before frame-plane allocation.
    • Validates decoded picture dimensions, pixel count, and checked RGBA8 byte size before calling Vec::try_reserve_exact, converting 8/10/12-bit YUV, GBR, YCgCo, monochrome, and alpha planes straight into the final RGBA8 buffer with no intermediate full-frame allocation.
    • Splits the 801-line crates/rune-image/src/avif.rs into crates/rune-image/src/avif/{mod,limits,codec,tests}.rs and removes unused transitive lodepng / quick-error dependencies as well as the NASM build requirement on x86_64.
  • Per-load caller pixel budgets: Added ImageLimits (with_max_side, with_max_pixels, with_max_alloc, clamped to Rune's global 8192 px / 67,108,864 px / 256 MiB cap) and ImageCache::load_with_limits / ImageCache::load_scaled_with_limits (re-exported as rune::ImageLimits).
    • Default ImageLimits shares cache keys with load/load_scaled; tighter limits use distinct cache keys so a rejected preview load never poisons a full-budget load.
    • Enforced consistently across native AVIF (preflight, rav1d, post-decode conversion), still rasters, animated GIF/WebP/APNG, SVG, and web header::check_with_limits + post-createImageBitmap checks.

Verification

  • Verified on Windows x86_64:
    • cargo test -p rune-image --features avif (106 passed, 2 ignored; 12 doc-tests passed), including direct rav1d frame_size_limit rejection tests (bypassing preflight) on www/public/img/hello-320.avif, real AV1 alpha-plane decode tests, and ImageCache::load_with_limits / load_scaled_with_limits cache-key isolation tests.
    • cargo test -p rune-image (102 passed, 2 ignored; 12 doc-tests passed) and 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).
    • bash scripts/file-size.sh (0 errors, 0 folder-shape issues).
  • Not run on real macOS, Linux, or live browser hardware.

Fixes #1719

…ImageLimits

Replace the `avif-decode` wrapper with direct `avif-parse`, pure-Rust `rav1d`, and `yuv` decoding inside `crates/rune-image/src/avif/`, so `Dav1dSettings::frame_size_limit` rejects oversized primary and alpha frames inside `rav1d` (`ERANGE`) before frame-plane allocation and converts decoded planes straight into a checked, `try_reserve_exact`-allocated RGBA8 buffer with no intermediate full-frame RGB/RGBA16 allocation.

Add `ImageLimits` (`max_side`, `max_pixels`, `max_alloc`, clamped to Rune's global cap) with `ImageCache::load_with_limits` and `ImageCache::load_scaled_with_limits` (re-exported as `rune::ImageLimits`) so callers with smaller preview surfaces can tighten per-load pixel budgets across native AVIF, raster, animated, SVG, and web header preflight paths.

Fixes #1719
@Hona
Hona merged commit 70f7a55 into dev Nov 27, 2026
2 checks passed
@Hona
Hona deleted the fix/avif-rav1d-budget branch November 27, 2026 15:21
pascalandr added a commit to NeuralNomadsAI/rune that referenced this pull request Nov 27, 2026
Upstream merged the first Android slice (anomalyco#2662, closing anomalyco#2647): the winit
activity feature, the getloadavg gate and an android workflow. Taken from
upstream: runq.rs, the Android target section of rune's Cargo.toml (the
fork's JNI, NDK and AccessKit dependencies now sit in it), android.yml and
the changelog entry; the fork's own S0 entry goes.

Also from upstream since the last merge:
- Cx::touch_controls and hover_none read the host's primary pointer
  (anomalyco#2638). The fork's cfg(android) constants go; the Android LayerHost
  calls set_touch_controls(true), as the iOS one does.
- rune-text's prewarm_system_fonts (anomalyco#2660): Android's backend answers it
  with nothing to build ahead.
- rav1d without assembly (anomalyco#2641): an x86_64 library with avif links
  without -Wl,-Bsymbolic, so ANDROID.md's note about it goes.

Kept over upstream in android.yml: the android/** push trigger and the apk
job, which builds the Kotlin host with the example.

Checked: clippy for both Android targets (let_underscore_must_use allowed,
as rune-core fails it upstream), an x86_64 cdylib with avif links,
check-wasm, cargo check, file-size, rune lib tests 4087 passed with the 4
failures upstream dev has on Windows (and one more that passes alone).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native AVIF: enforce the pixel budget in rav1d and before RGBA conversion

1 participant