bytecodealliance / bytecodealliance/wizer

Wizer truncates data segment count to 10000, resulting in out-of-bounds indices

Open
#126 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.1k
Forks
64
PR merge metrics
No merged PRs in 30d

Description

I am running wizer on a large wasm file with 80390 data segments (I can provide it on request). The file output by wizer does preserve my data segments but the count value is truncated to 10000, resulting in a malformed wasm file according to tools like wasm-dis and wasm-opt since the naming section is still referring to the old indices.

Before:
```
0x11a8c | 09 c4 a6 05 | element section
0x11a90 | 01 | 1 count
0x11a91 | 00 | element table[None]
0x11a92 | 41 01 | i32_const value:1
0x11a94 | 0b | end
0x11a95 | e3 81 02 | 32995 items [indices]
... 32995 lines removed ...
0x26dd4 | 0c 03 | data count section
0x26dd6 | 86 f4 04 | data count 80390
0x26dd9 | 0a fa ef ca | code section
| 06
0x26dde | 95 f8 02 | 48149 count
```
After:

```
0x11a78 | 09 c4 a6 05 | element section
0x11a7c | 01 | 1 count
0x11a7d | 00 | element table[None]
0x11a7e | 41 01 | i32_const value:1
0x11a80 | 0b | end
0x11a81 | e3 81 02 | 32995 items [indices]
... 32995 lines removed ...
0x26dc0 | 0c 02 | data count section
0x26dc2 | 90 4e | data count 10000
0x26dc4 | 0a fa ef ca | code section
| 06
0x26dc9 | 95 f8 02 | 48149 count
```

Causing tools like wasm-dis to output this warning:
```
warning: data index out of bounds in name section: .rodata.10000 at index 10000
```
And wasm-opt to fail more explosively with this:
```
wasm-opt: /b/s/w/ir/cache/builder/emscripten-releases/binaryen/src/wasm/wasm.cpp:1833: void wasm::Module::updateDataSegmentsMap(): Assertion `dataSegmentsMap.size() == dataSegments.size()' failed.
```

Since the resulting file still contains up to this:
```
0x267d509 | 85 f4 04 0d | Naming { index: 80389, name: ".rodata.80389" }
| 2e 72 6f 64
| 61 74 61 2e
| 38 30 33 38
| 39
```

I guess there might be a bug that it doesn't rewrite the indices, but I would question why there is such a small limit to begin with.

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.