bytecodealliance / bytecodealliance/wasm-tools

`wasmparser`: Valid Wasm is not accepted if `bulk-memory` is enabled and `reference-types` is disabled

Open
#889 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.8k
Forks
351
Avg merge
1d 6h
Merged PRs (30d)
46

Description

I stumbled upon this when implementing `bulk-memory` Wasm proposal support in `wasmi` when integrating the new Wasm spec testsuite test cases for the `bulk-memory` Wasm proposal. Note: `wasmi` does not yet have support for the `reference-types` Wasm proposal and I guess this is important for this issue.

Namely, when parsing and validating the test cases via `wasmparser` (as always) it errors out with this message among others:

```shell
---- spec::bulk_memory::wasm_table_copy stdout ----
thread 'spec::bulk_memory::wasm_table_copy' panicked at 'tests/spec/testsuite/proposals/bulk-memory-operations/table_copy.wast: failed to execute `.wast` directive: reference types support is not enabled (at offset 0x74)', crates\wasmi\tests\spec\run.rs:44:9

---- spec::bulk_memory::wasm_table_init stdout ----
thread 'spec::bulk_memory::wasm_table_init' panicked at 'tests/spec/testsuite/proposals/bulk-memory-operations/table_init.wast: failed to execute `.wast` directive: reference types support is not enabled (at offset 0x74)', crates\wasmi\tests\spec\run.rs:44:9
```

The `wasmparser` error message is: `reference types support is not enabled (at offset 0x74)`
Querying the `wasmparser` codebase got me the following code segments:

---

https://github.com/bytecodealliance/wasm-tools/blob/cacda73ccb6f9f8cc42e8391c77480187c99b48d/crates/wasmparser/src/validator.rs#L256

Which filters out `ValType::FuncRef | ValType::ExternRef` types, however, the `bulk-memory` Wasm proposal explicitly allows `ValType::FuncRef` in so-called `elemexpr` which can only occur in Wasm element const experessions. I think this is the problematic code. (Not tested though.)
```lex
elemexpr = refnull | funcref
```
Source: [`bulk-memory` Wasm Proposal Overview](https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md)
![elemexpr](https://user-images.githubusercontent.com/8193155/214364222-ddf42046-5294-43d3-b09b-8401bc98f09e.png)

---

https://github.com/bytecodealliance/wasm-tools/blob/cacda73ccb6f9f8cc42e8391c77480187c99b48d/crates/wasmparser/src/validator/operators.rs#L934

Unfortunately I am on `wasmparser 0.91` so this issue might have already been resolved in a newer version.
Here is a [link to the WIP `wasmi` PR](https://github.com/paritytech/wasmi/pull/628) in case this helps. (It is very WIP ...)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.