bytecodealliance / bytecodealliance/wasm-tools

wasm_encoder does not increase TypeSection num_added length proportionally to amount of types in recursive type

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

Description

https://github.com/bytecodealliance/wasm-tools/blob/04ca1c576ebf1fe424b21f687eed6813c4231974/crates/wasm-encoder/src/core/types.rs#L615

Is this the correct behavior? I'm generating a module in Rust but it does so incorrectly as I have a recursive type get added with multiple entries, and so .len() on the TypeSection is desynchronized. The type indices I use after the fact are then invalid and pointing to the wrong thing. pseudo-code-ish example of what I mean:

```Rust
let types = TypeSection::new();
let funcs = FunctionSection::new();

types.rec([SubType { .. }, SubType { .. }]);

let func_type_id = types.len(); //Expected: 2; Got: 1
types.func([ValType::I32], [ValType::I32]);
funcs.function(func_type_id); //Invalid
```

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.