Skip to content

Avoid overflow in component ABI size calculations - #14058

Open
subotac wants to merge 2 commits into
bytecodealliance:mainfrom
subotac:fix/component-abi-size-overflow
Open

Avoid overflow in component ABI size calculations#14058
subotac wants to merge 2 commits into
bytecodealliance:mainfrom
subotac:fix/component-abi-size-overflow

Conversation

@subotac

@subotac subotac commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #13980.

Preserve the canonical ABI size overflow sentinel when aligning and composing record and variant layouts and when advancing field offsets.

Add regression coverage for dynamic and const record/variant layouts and 32-/64-bit field offsets.

Tests:

  • cargo test -p wasmtime-environ --features component-model
  • cargo clippy -p wasmtime-environ --features component-model --all-targets -- -D warnings
  • cargo fmt -p wasmtime-environ -- --check

@subotac
subotac requested a review from a team as a code owner August 1, 2026 09:56
@subotac
subotac requested review from dicej and removed request for a team August 1, 2026 09:56
@alexcrichton

Copy link
Copy Markdown
Member

This feel s a bit too coarse to me to just slap .saturating_* everywhere and return, for example, explicitly unaligned sizes on align_to on overflow. With your understanding of this issue do you know of a more targeted fix?

Signed-off-by: subotac <73706465+subotac@users.noreply.github.com>
@subotac

subotac commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — I narrowed the fix in 3ca57dd. align_to and the next_field* helpers now retain their original strict behavior. Only cached record/variant ABI size composition uses u64 intermediates and saturates at
u32::MAX, matching the existing fixed-length-list size representation. I also replaced the broad unit test with the issue reproducer in the fixed-length-list WAST suite.

@alexcrichton

Copy link
Copy Markdown
Member

Thanks for the updates, but reading over this again I continue to be left with a bit of unease about fixing this issue here. I think I'd personally prefer to go the route of WebAssembly/component-model#682 and fix this at the component-model validation layer rather than in a bit of an ad-hoc fashion within Wasmtime here. I'd ideally like to take that as an opportunity to flesh out the tests here and expand them, too.

I don't believe that this is is a major issue for preexisting components and currently the only issue is when dealing with fixed-length-lists, so I think it's ok to leave this un-fixed on main for a bit personally.

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.

Fixed-length lists can overflow in ABI calculations for the size of the list

2 participants