bytecodealliance / bytecodealliance/wasm-tools

Listing exports from wasm-smith-generated modules

Open
#1,041 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.8k
Forks
351
Avg merge
16h 57m
Merged PRs (30d)
38

Description

Hey! So I’m trying to list the exports of modules generated by wasm-smith.

My first attempt was the following:
```rust
fuzz_target!(|data: wasm_smith::Module| {
let bytes = data.to_bytes();
let module = wasmparser::validate(&bytes).expect("wasm-smith-generated module is invalid");
if module.module_count() < 1 {
return;
}
let exports = &module
.module_at(0)
.expect("wasm-smith-generated module does not have one module")
.exports;
// ...
});
```

Except… it turns out `module.module_count()` apparently is always 0.

I managed to do what I wanted with the following:
```rust

fuzz_target!(|data: wasm_smith::Module| {
let bytes = data.to_bytes();
let mut exports = Vec::new();
for s in wasmparser::Parser::new(0).parse_all(&bytes) {
let s = s.expect("wasm-smith-generated module is invalid");
if let wasmparser::Payload::ExportSection(s) = s {
for e in s.into_iter() {
let e = e.expect("wasm-smith-generated module is invalid");
exports.push(e.name.to_owned());
}
}
}
// ...
});
```

But I’m wondering… is the first one not supposed to be the same? It’s been hard finding documentation on `Types`, but my understanding of it is it should also list all the exports?

(If not, let’s have this issue serve as google-able "documentation" for how to do it :))

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.