Skip to content

fix(image): AVIF dimensions and decode size are checked before the raster is decoded - #1516

Merged
Hona merged 1 commit into
devfrom
fix/888-avif-dimension-check
Nov 23, 2026
Merged

Hona merged 1 commit into
devfrom
fix/888-avif-dimension-check

Conversation

@Hona

@Hona Hona commented Nov 23, 2026

Copy link
Copy Markdown
Member

Fixes #888

Root cause

  • crates/rune-image/src/avif.rs: rgba called avif_decode::Decoder::from_avif(bytes)?.to_image() and only then compared w/h against 8192.
  • crates/rune-image/src/lib.rs decode sends AVIF to avif::rgba before it builds the image::Limits (8192 px, 256 MiB) that other raster formats get.
  • So a few-KB AVIF that declares 16384 x 16384 made rav1d and the YUV-to-RGB step allocate about 1 GiB before the image was refused.

Change

flowchart LR
  bytes --> check["limits::check (headers only)"]
  check -- "over 8192 px or 256 MiB" --> err["AVIF is too large"]
  check -- ok --> decode["avif_decode::to_image"] --> mips
Loading
  • New avif::limits::check runs before avif-decode. It reads headers only and allocates no pixels:
    • ISO-BMFF boxes, with every box size, iloc count and extent kept inside the input.
    • ispe of the primary item and of its alpha (auxl + alpha auxC) item.
    • Each AV1 sequence header in those items (max_frame_width/height, bit depth, monochrome).
    • A frame header with frame_size_override_flag, because rav1d takes those sizes without comparing them to the sequence maximum.
  • Limits match the image path: at most 8192 px per side, and at most 256 MiB for the decoder's output buffer (16-bit RGBA counts 8 bytes per pixel).
  • The old check after decoding stays as a backstop.
  • Tests in avif_tests.rs build small AVIF containers and OBUs in code. No test files are committed.

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.

AVIF: the raster is decoded before its dimensions are checked, so a small file can allocate about 1 GiB

1 participant