Skip to content

Wasm-smith's --exports option does not support exporting globals with GC types #2250

Open
@mobsceneZ

Description

@mobsceneZ

When providing the following module to the --exports option, wasm-smith panicked with the error messsage "called Result::unwrap() on an Err value: CanonicalizedHeapTypeReference":

(module
  (rec (type $t0 (sub final (array i32))))
  (global $g1 (mut (ref null $t0)) ref.null $t0)
  (export "global$1" (global $g1))
)

A quick look at the source code reveals that the problem is with the entity_type_from_export() function:

let new_index = match exports_types
.entity_type_from_export(&export)
.unwrap_or_else(|| {
panic!("Unable to get type from export {export:?} in `exports` Wasm",)
}) {

It returns a wasmparser::GlobalType that contains canonicalized CoreTypeId. Then, the TryFrom trait implementation is called to convert the original wasmparser::GlobalType into wasm_encoder::GlobalType, but the conversion demands type space indices rather than core type ids, which eventually results in a panic.

I guess maybe we could remove the validation code inside _required_exports function? The _arbitrary_imports_from_available function doesn't seem to perform any validity checks too, so probably it's ok to do so 🤔.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wasm-smithRelated to the wasm-smith crate and creating wasm modules for fuzzing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions