Skip to content

Reject (ref ...) value types without function-references - #2864

Merged
sbc100 merged 2 commits into
WebAssembly:mainfrom
aizu-m:function-references-value-type-gate
Oct 28, 2026
Merged

sbc100 merged 2 commits into
WebAssembly:mainfrom
aizu-m:function-references-value-type-gate

Conversation

@aizu-m

@aizu-m aizu-m commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

PeekMatchRefType() admits (ref ...) when either function-references or exceptions is enabled. Exceptions is on by default and function-references is off, so with no flags the shorthand (ref func), the index form (ref 0) and the named form (ref $t) all reach the typed reference parsing paths. The named form then trips assert(function_references_enabled()) in ParseValueTypeList and ParseBoundValueTypeList, an abort in assert-enabled builds reachable from untrusted .wat through wat2wasm and wast2json.

The exceptions condition came in with #2497, but nothing there needs it. The exception-handling spec tests only use the ref.null exn instruction, never a (ref ...) type. This gates PeekMatchRefType() on function-references alone, so every (ref ...) form is rejected with the parser's usual unexpected-token error when the feature is off, and the two asserts hold again. exnref and ref.null exn still parse with exceptions on, and --enable-function-references is unchanged.

Found by fuzzing the wat2wasm harness. Full run-tests.py suite and the 135 gtests pass.

@zherczeg

Copy link
Copy Markdown
Collaborator

Why rejecting named refs only? Without typed function references (ref ...) should not work.

PeekMatchRefType() also admitted (ref ...) when only exceptions was
enabled, so the shorthand, index and named forms all reached the typed
reference parsing paths with function-references off. Gate it on
function-references alone, which restores the asserts in
ParseValueTypeList and ParseBoundValueTypeList, and cover every form in
the test.
@aizu-m aizu-m changed the title Reject named reference value types without function-references Reject (ref ...) value types without function-references Sep 25, 2026
@aizu-m

aizu-m commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

Agreed. The exceptions condition in PeekMatchRefType() was letting (ref func), (ref 0) and (ref $t) all through with default flags, and only the named form happened to hit the assert. It came in with #2497, but the EH spec tests only use ref.null exn, never a (ref ...) type, so nothing needs it.

Pushed a version that gates PeekMatchRefType() on function-references alone. Every (ref ...) form is now rejected without the flag, the two asserts are back as they were, and the test covers the shorthand, index, named and local forms. Full suite and gtests pass.

@zherczeg zherczeg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@aizu-m

aizu-m commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

gentle ping

@sbc100
sbc100 merged commit 61e851a into WebAssembly:main Oct 28, 2026
17 checks passed
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.

3 participants