-
Notifications
You must be signed in to change notification settings - Fork 295
Description
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:
wasm-tools/crates/wasm-smith/src/core.rs
Lines 1971 to 1975 in bc0a785
| 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 🤔.