Skip to content

Should types have a spec-mandated maximum size? #682

Closed

Description

@alexcrichton

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.

Activity

  1. lukewagner commented on Jul 27, 2026

    @lukewagner
    Member

    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?

  2. alexcrichton commented on Jul 27, 2026

    @alexcrichton
    CollaboratorAuthor

    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

  3. ANAMASGARD commented on Aug 16, 2026

    @ANAMASGARD
    Contributor

    @alexcrichton I have raised a PR to fix this issue please can review it and give your feedback thanks
    #688

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions