Skip to content

Specify maximum static size for component value types - #688

Open
ANAMASGARD wants to merge 6 commits into
WebAssembly:mainfrom
ANAMASGARD:fix/component-type-size-limit
Open

Specify maximum static size for component value types#688
ANAMASGARD wants to merge 6 commits into
WebAssembly:mainfrom
ANAMASGARD:fix/component-type-size-limit

Conversation

@ANAMASGARD

Copy link
Copy Markdown

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 <chaudharygaurav2004@gmail.com>
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 <chaudharygaurav2004@gmail.com>
@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 <chaudharygaurav2004@gmail.com>
@ANAMASGARD

ANAMASGARD commented Aug 16, 2026

Copy link
Copy Markdown
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 Outdated
Comment thread design/mvp/Explainer.md Outdated
Comment thread design/mvp/CanonicalABI.md Outdated
Comment thread design/mvp/Binary.md Outdated
Comment thread test/validation/max-value-size.wast Outdated
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 <chaudharygaurav2004@gmail.com>
@ANAMASGARD

Copy link
Copy Markdown
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 Outdated
Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
@ANAMASGARD

Copy link
Copy Markdown
Author

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

@ANAMASGARD
ANAMASGARD requested a review from lukewagner August 18, 2026 02:14
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