Repository navigation
fix(image): web images have their header dimensions checked before the browser decodes them - #1559
Merged
Merged
Conversation
…e browser decodes them
This was referenced Nov 23, 2026
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 #1422
What was wrong
crates/rune-image/src/from_url.js(blobRgba) calledcreateImageBitmapfirst and checkedmaxSideonly afterwards. A small PNG, JPEG, GIF or WebP that declares a huge raster made the browser decode the whole raster before Rune refused it.ImageCache::url/file(fetchImage) andImageCache::load(decodeImage).What changed
crates/rune-image/src/header.rsreads the declared size from the header, without decoding, for every format the web path gives to the browser:IHDRSOFn(skips APPn segments, so an EXIF thumbnail cannot hide the main frame)VP8/VP8L/VP8X, plus nestedVP8/VP8L/ANMFchunksavif::limits::checkthat native AVIF decoding uses (fix(image): AVIF dimensions and decode size are checked before the raster is decoded #1516)MAX_SIDE(8192) andMAX_ALLOC(256 MiB) are now defined once inlib.rs. The nativeimage::Limits, the AVIF limits, animations, mips, pixels and the web check all use these constants, so the web and native limits cannot drift apart.from_url.js:fetchBytesreturns the raw bytes to Rust, which checks them beforedecodeImagecallscreateImageBitmap. The check after decoding stays as a second guard.Notes
header_tests.rsbuilds each header from a few bytes in the test: valid sizes, the limit, one pixel over the limit, zero sizes, and attempts to hide a large frame inside a small container (a GIF frame, WebPVP8XwithVP8L/ANMF, ICO payloads, AVIF with a smallispebut a large AV1 header). It also encodes small real PNG, JPEG, GIF, WebP, BMP and ICO images withimageand checks that they pass.wasm32-unknown-unknown(rune-imageandrune --no-default-features) but was not run in a browser.