Stream: git-wasmtime

Topic: wasmtime / PR #11690 Wasmtime: enforce function-body-size...


view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2025 at 00:05):

cfallin opened PR #11690 from cfallin:wasm-impl-limit-function-size to bytecodealliance:main:

In #11682 we see a module with an extremely large single function body (function index 193). This causes a panic in Cranelift as we run out of SSA value numbers: the ValueDataPacked bit-packing supports only 2^24 (16M) values per function.

I started down the path of propagating CodegenErrors everywhere throughout Cranelift to properly bubble up a
CodegenError::CodeTooLarge, but that turns out to be an extremely pervasive change: it means not only that we have more Result plumbing, but that (i) Cranelift's public API changes so that all function builder methods return Results, which is a huge change for any existing user; and (ii) ISLE can't generate Rust that propagates Results, so we need to awkwardly set an error flag on a context, return a fake Value, and "catch" it on the other side of the invocation, which is error-prone.

I then considered a size-check on function bodies as they enter Cranelift, but at that point, realized that Wasm already provides for implementation limits for this purpose. The JS embedding spec at https://webassembly.github.io/spec/js-api/index.html#limits specifies that a function body can be at most 7_654_321 bytes (7.65MB). We don't have to follow the JS embedding's implementation limits, but there is good reason to expect that producers will try to stay within them, and the reasons that led to those limits in Web engines' compilers equally apply to ours. This PR thus instead enforces the limit directly.

Fixes #11682.

<!--
Please make sure you include the following information:

Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.html

Please ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2025 at 00:05):

cfallin requested fitzgen for a review on PR #11690.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2025 at 00:05):

cfallin requested wasmtime-compiler-reviewers for a review on PR #11690.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2025 at 00:05):

cfallin requested wasmtime-core-reviewers for a review on PR #11690.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2025 at 15:41):

fitzgen commented on PR #11690:

It might be better to enforce this in wasmparser, where we enforce the rest of these implementation limits:

https://github.com/bytecodealliance/wasm-tools/blob/35f8671bce74190ef0b00ce36c399b053b490374/crates/wasmparser/src/limits.rs#L18-L44

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2025 at 17:09):

cfallin commented on PR #11690:

Good point -- opened https://github.com/bytecodealliance/wasm-tools/pull/2302 for this.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2025 at 17:09):

cfallin closed without merge PR #11690.


Last updated: Dec 06 2025 at 07:03 UTC