ref.test and ref.cast accept a target heap type from a different hierarchy than the operand
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 512
- Forks
- 51
- Avg merge
- 7h 34m
- Merged PRs (30d)
- 21
Description
ref.test and ref.cast validate (and run) with a target heap type that is in a different type hierarchy than the operand — e.g. ref.test (ref extern) / ref.cast (ref extern) applied to an (ref i31) value. The spec requires the target reference type and the operand type to share a common top (the same hierarchy: any / func / extern), so these modules are ill-typed; wasm-tools, V8 and wasmtime all reject them at validation, but Wizard accepts and runs them.
Minimal repros
;; ref.test — accepts, and returns a (wrong) positive result
(module (func (export "f") (result i32)
(ref.test (ref extern) (ref.i31 (i32.const 5))))) ;; Wizard: 1 conformant: REJECT
;; ref.cast — accepts, then runs (or runtime-traps FAILED_CAST)
(module (func (export "f") (result i32)
(drop (ref.cast (ref extern) (ref.i31 (i32.const 5)))) (i32.const 7))) ;; Wizard: 7 conformant: REJECT
| program | wasm-tools / V8 / wasmtime | Wizard 26.1 |
|---|---|---|
ref.test (ref extern) on (ref i31) |
REJECT (expected externref, found (ref i31)) |
accepts, returns 1 (claims an i31 is an extern) |
ref.test (ref func) on a struct |
REJECT | accepts, returns 0 |
ref.cast (ref extern) on (ref i31) |
REJECT | accepts, runs, returns 7 |
ref.cast (ref func) on a struct |
REJECT | accepts, then runtime-traps FAILED_CAST |
ref.cast (ref null i31) on (ref.null func) |
REJECT | accepts, ref.is_null → 1 |
Scope
- Affects the
ref.test/ref.castpair.br_on_castandbr_on_cast_failcorrectly reject the same cross-hierarchy operands at validation, so the missing check is localized toref.test/ref.cast. - Same-hierarchy controls validate and run correctly on every engine:
ref.test (ref i31)on an(ref i31)value → 1.
Per the spec, ref.test rt / ref.cast rt are well-typed only if the operand's type and rt have a common supertype (the test/cast is within one hierarchy); a cross-hierarchy test/cast is unrepresentable and must be rejected at validation.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the validation handling for the ref.test and ref.cast instructions and run the minimal repro modules from the issue. Add coverage for cross-hierarchy operands such as (ref extern) with (ref i31), and consider the work done when both instructions reject these modules while same-hierarchy cases continue to validate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- wasm
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100