Skip to content

Fix/improve validation of components with tags #2114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

alexcrichton
Copy link
Member

This commit fixes an issue where the Tag kind of core item was allowed to "leak through" validation of components without the exceptions proposal active. Additionally creating a core instance with a tag was consulting the wrong index space and needed fixing too. The end result is that the exceptions proposal is now required for tags to appear within components.

This so far has been glossed over because any valid component would require a core module with a tag and those are properly gated, but it's possible to construct an invalid component with a tag "kind" within it which doesn't actually have any tags. By forgetting to gate on the exception-handling proposal it was leaking this "kind" to callers which weren't necessarily prepared for it.

Finally this also fixes a panic in the text format for components where named tags still had an unimplemented!() for when they were being registered.

This commit fixes an issue where the `Tag` kind of core item was allowed
to "leak through" validation of components without the exceptions
proposal active. Additionally creating a core instance with a tag was
consulting the wrong index space and needed fixing too. The end result
is that the `exceptions` proposal is now required for tags to appear
within components.

This so far has been glossed over because any valid component would
require a core module with a tag and those are properly gated, but it's
possible to construct an invalid component with a tag "kind" within it
which doesn't actually have any tags. By forgetting to gate on the
exception-handling proposal it was leaking this "kind" to callers which
weren't necessarily prepared for it.

Finally this also fixes a panic in the text format for components where
named tags still had an `unimplemented!()` for when they were being
registered.
@alexcrichton
Copy link
Member Author

Thanks to @0xalpharush for identifying this in Wasmtime which led to this bugfix here

alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Mar 26, 2025
This commit resolves a few panics in Wasmtime's compilation of
components with respect to tags and the exception-handling wasm
proposal. Despite exception-handling not being enabled in Wasmtime at
this time these panics were still reachable due to an issue in
wasm-tools's validation not being exhaustive enough for this proposal
feature combination: bytecodealliance/wasm-tools#2114.

This is not full support for exceptions since it can't be tested yet,
but this should be enough to ensure that the validator will get far
enough to flag components as otherwise invalid due to using tags that
can't be present (as core wasm tags can't be present in core modules
right now, the `EXCEPTIONS` feature is always disabled).
@@ -0,0 +1,18 @@
;; RUN: wast --features=-exceptions %
Copy link
Member Author

Choose a reason for hiding this comment

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

All of our existing *.wast tests also do --assert default with --snapshot ..., but personally I find it kind of a pain to set that all up and manage it, so my thinking is that it's reasonable to have one-off tests like this which just run the directives themselves.

github-merge-queue bot pushed a commit to bytecodealliance/wasmtime that referenced this pull request Mar 26, 2025
This commit resolves a few panics in Wasmtime's compilation of
components with respect to tags and the exception-handling wasm
proposal. Despite exception-handling not being enabled in Wasmtime at
this time these panics were still reachable due to an issue in
wasm-tools's validation not being exhaustive enough for this proposal
feature combination: bytecodealliance/wasm-tools#2114.

This is not full support for exceptions since it can't be tested yet,
but this should be enough to ensure that the validator will get far
enough to flag components as otherwise invalid due to using tags that
can't be present (as core wasm tags can't be present in core modules
right now, the `EXCEPTIONS` feature is always disabled).
@fitzgen fitzgen added this pull request to the merge queue Mar 26, 2025
Merged via the queue into bytecodealliance:main with commit 4af626c Mar 26, 2025
32 checks passed
@alexcrichton alexcrichton deleted the fix-components-and-tags branch March 27, 2025 03:27
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.

2 participants