Return an error instead of panicking on fixed-length-list size overflow - #2643
Merged
alexcrichton merged 2 commits intoSep 8, 2026
Merged
Conversation
`SizeAlign::fill` (and its internal `calculate` helper) computed the
size of a `FixedLengthList` as `element_size * length` via
`checked_mul(..).unwrap()`, which panics when the multiplication
overflows `usize`. Since `list<T, N>` places no upper bound on `N` in
the WIT text format (unlike the component binary format, which bounds
it to `MAX_WASM_FIXED_LENGTH_LIST_ELEMENTS`), a WIT document with two
nested fixed-length lists of a non-trivial element type is enough to
overflow the multiplication and abort the process, in a release build
too.
This changes `SizeAlign::fill`/`calculate` to return `anyhow::Result`
and propagates that outward through `wit-dylib`'s `Adapter::encode`,
`create`, and `create_with_metadata`, and their two call sites (the
`wasm-tools wit-dylib` CLI subcommand and the wit-dylib test-programs
harness). A oversized fixed-length list now surfaces as a normal
error instead of aborting:
$ wasm-tools wit-dylib poc.wit
error: size of fixed-length list of 4294967295 elements overflows
the target architecture's address space
Adds a regression test covering both the overflow case (now returns
`Err`) and a benign nested fixed-length list (still computes
correctly).
Fixes bytecodealliance#2637
pchickey
approved these changes
Sep 8, 2026
find_signed_load's test helper still called super::create() as if it returned Vec<u8> directly; it now returns anyhow::Result<Vec<u8>>. Caught by CI's clippy job (which builds --all-targets, unlike my local clippy run that only covered the lib). Did an exhaustive grep across the whole workspace afterward for every other Adapter/SizeAlign call site to confirm this was the only one missed.
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.
SizeAlign::fill(and its internalcalculatehelper) computed the size of aFixedLengthListaselement_size * lengthviachecked_mul(..).unwrap(), which panics when the multiplication overflowsusize. Sincelist<T, N>places no upper bound onNin the WIT text format (unlike the component binary format, which bounds it toMAX_WASM_FIXED_LENGTH_LIST_ELEMENTS), a WIT document with two nested fixed-length lists of a non-trivial element type is enough to overflow the multiplication and abort the process, in a release build too.This changes
SizeAlign::fill/calculateto returnanyhow::Resultand propagates that outward throughwit-dylib'sAdapter::encode,create, andcreate_with_metadata, and their two call sites (thewasm-tools wit-dylibCLI subcommand and the wit-dylib test-programs harness). A oversized fixed-length list now surfaces as a normal error instead of aborting:Adds a regression test covering both the overflow case (now returns
Err) and a benign nested fixed-length list (still computes correctly).Fixes #2637