You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should types have a spec-mandated maximum size? #682
When reviewing the implementation of fixed-length-lists throughout Wasmtime/wasm-tools one of the primary things I've seen is the hazard of overflows that are possible when calculating the size of a fixed-length-list. This is the first component model type where the size of the value is variable depending on the definition (statically at least, as opposed to lists which are runtime-variable-sized). It's quite easy to just multiple the element size and list size together and ignore overflow, and this has led to a number of bugs or potential bugs in wasm-tools and Wasmtime. Personally I see this as a potential security hazard because it's quite easy for the host to hit these overflow cases.
I'd like to propose the possible idea of capping the size of all component model values in the specification itself. For example disallowing any fixed-length-list above 16M or something large-ish like that. This would apply to all preexisting types and additionally handle something like (tuple $big-list $big-list). Currently in wasm-tool there's already a limit to "type complexity" of sorts where everything is counted in the recursive tree and the sum needs to be below a fixed amount. Capping the maximum size of the list, however, is probably a better heuristic.
Effectively what I'd like to do is to put the complicated overflow/ABI logic in one place, the component validator, and then not have to worry anywhere else about this. Right now Wasmtime has a few potential would-be-CVEs if fixed-length-lists were stable, and I feel that without having checks on the size of values it's too easy for runtimes to run into overflow situations.
That makes sense to me. There's already a spec-defined elem_size(t) which is "the byte size of t in memory as the elements of a list", so we could refer to that as part of the validation of t. If so, elem_size(t) would cover everything except the dynamic string/list element allocations, which are already dynamically guarded by MAX_{STRING,LIST}_BYTE_LENGTH. My impression is that, given their dynamically-sized nature, we'd want to keep these with a higher-limit (currently 228) than the 16M-or-so limit you're suggesting for values; yes?
On second thought 256M (2^28 I think right?) seems reasonable to me as well. That rules out most overflow cases for example when doubling/adding two things together they are guaranteed to never overflow even i32. So if that's already the max for strings/lists I think it'd be reasonable to apply that to all types
Activity
lukewagner commentedon Jul 27, 2026
That makes sense to me. There's already a spec-defined
elem_size(t)which is "the byte size oftin memory as the elements of a list", so we could refer to that as part of the validation oft. If so,elem_size(t)would cover everything except the dynamic string/list element allocations, which are already dynamically guarded byMAX_{STRING,LIST}_BYTE_LENGTH. My impression is that, given their dynamically-sized nature, we'd want to keep these with a higher-limit (currently 228) than the 16M-or-so limit you're suggesting for values; yes?alexcrichton commentedon Jul 27, 2026
On second thought 256M (2^28 I think right?) seems reasonable to me as well. That rules out most overflow cases for example when doubling/adding two things together they are guaranteed to never overflow even
i32. So if that's already the max for strings/lists I think it'd be reasonable to apply that to all typesFix nested despecialization in value type size validation.
ANAMASGARD commentedon Aug 16, 2026
@alexcrichton I have raised a PR to fix this issue please can review it and give your feedback thanks
#688
Specify maximum static size for component value types (#688)