Skip to content

Specify maximum static size for component value types - #688

Merged
lukewagner merged 6 commits into
WebAssembly:mainfrom
ANAMASGARD:fix/component-type-size-limit
Aug 20, 2026
Merged

lukewagner merged 6 commits into
WebAssembly:mainfrom
ANAMASGARD:fix/component-type-size-limit

Conversation

@ANAMASGARD

Copy link
Copy Markdown
Contributor

Fixes #682

Summary

Adds a spec-defined maximum static value size of 2^28 - 1 bytes for Component Model value types.

Validation now:

  • checks both i32 and i64 pointer types;
  • uses overflow-safe size calculations;
  • validates nested/despecialized types recursively;
  • rejects oversized types during validation instead of at runtime.

Includes Python and WAST regression tests for fixed-length lists, compound types, nested maps, pointer-width differences, and integer-overflow cases.

The WAST test remains in nyi.txt until wasm-tools/Wasmtime implement the corresponding validator rule.

Require resolved type AST nodes to satisfy elem_size <= 2^28 - 1 for
both i32 and i64 pointer types using overflow-safe validation, closing
fixed-length-list sizing hazards (WebAssembly#682).

Signed-off-by: Gaurav Chaudhary <[email protected]>
Apply despecialize at each recursive check_resolved_type_size call so
nested map/option/record nodes are validated, not only top-level types.
Add regression tests for option<map<...>> and record fields (WebAssembly#682).

Signed-off-by: Gaurav Chaudhary <[email protected]>
@lukewagner

Copy link
Copy Markdown
Member

Thanks for working on this! To resolve #682, I had been thinking that perhaps we could reuse the elem_size function as already defined, and simply add validation notes mentioning it in all the relevant places: Explainer.md, Binary.md, and canonopt validation. That should then reduce the size of the PR.

ANAMASGARD and others added 2 commits August 16, 2026 12:10
Replace the duplicate checked_* Python with one Element Size invariant
(every despecialized AST node, both pointer widths) and short pointers in
Binary, Explainer, and canonopt validation. Keep WAST coverage and drop
the run_tests.py validator tests.

Signed-off-by: Gaurav Chaudhary <[email protected]>
@ANAMASGARD

ANAMASGARD commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor Author

@lukewagner Thanks for the feedback

Validation now reuses the existing elem_size definition instead of adding a separate checked_* algorithm. The full rule is in Element Size in CanonicalABI.md (every despecialized AST node, both i32 and i64), with short pointers in Explainer.md, Binary.md, and canonopt validation. WAST tests cover the edge cases; nyi.txt until wasm-tools/Wasmtime implement the validator.

@alexcrichton please review this PR and give your feedback , thanks

@alexcrichton

Copy link
Copy Markdown
Collaborator

This seems fine by me modulo precise spec text yeah, it's what I was imagining on #682 at a high level

@lukewagner lukewagner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me; thanks! A few requested changes and then I expect it'll be good to go.

Comment thread design/mvp/CanonicalABI.md Resolved
Comment thread design/mvp/Explainer.md Resolved
Comment thread design/mvp/CanonicalABI.md Resolved
Comment thread design/mvp/Binary.md Resolved
Comment thread test/validation/max-value-size.wast Resolved
Use Luke's i64 Element Size validation notes and fold valid WAST
types into one component with boundary compound cases.

Signed-off-by: Gaurav Chaudhary <[email protected]>
@ANAMASGARD

Copy link
Copy Markdown
Contributor Author

@lukewagner & @alexcrichton Thank you so much for the review .
I have applied the requested wording and placements : Element Size intro + Binary/canonopt notes, Explainer paragraph moved next to defvaltype. WAST now has one valid component (including just-under-bound compounds); assert_invalid covers types whose elem_size(t, i64) is not less than 2^28.

@ANAMASGARD
ANAMASGARD requested a review from lukewagner August 17, 2026 17:52

@lukewagner lukewagner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks.

Comment thread design/mvp/Binary.md Resolved
@ANAMASGARD

Copy link
Copy Markdown
Contributor Author

@lukewagner I have wrapped the Binary.md validation bullet as requested.

@ANAMASGARD
ANAMASGARD requested a review from lukewagner August 18, 2026 02:14
@lukewagner
lukewagner merged commit ce4fb2b into WebAssembly:main Aug 20, 2026
1 check passed
alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Aug 27, 2026
This commit is an implementation of WebAssembly/component-model#688
where the in-memory size of component model types is now calculated and
validated to be below the static threshold. The eventual goal of this
implementation is to simplify logic in Wasmtime for example and reduce
the affect/possibility of integer overflow when handling otherwise very
large types. The limits here are large enough that all preexisting
components are expected to continue to validate.
github-actions Bot pushed a commit to SavantEnvs/wasm-tools that referenced this pull request Aug 29, 2026
This commit is an implementation of WebAssembly/component-model#688
where the in-memory size of component model types is now calculated and
validated to be below the static threshold. The eventual goal of this
implementation is to simplify logic in Wasmtime for example and reduce
the affect/possibility of integer overflow when handling otherwise very
large types. The limits here are large enough that all preexisting
components are expected to continue to validate.
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.

Should types have a spec-mandated maximum size?

3 participants