Commit 0ef5bd9
authored
[interp] Pop memory.copy/table.copy length using the minimum index type (WebAssembly#2800)
A valid module doing a mixed-width `table.copy` aborts wasm-interp in a
debug build:
$ wasm-interp --enable-memory64 --enable-multi-memory --run-all-exports
t.wasm
Assertion failed: (t == type || type == ValueType::Any), function
CheckType, file interp.h, line 596.
The module copies from an i64-indexed table into an i32-indexed one
(`table.copy $t32 $t64`). Found it running the memory64 tests under
`--run-all-exports`.
`DoTableCopy`/`DoMemoryCopy` pop the length operand with the source's
index type (`PopPtr(table_src)`/`PopPtr(mem_src)`). But the length's
type is the minimum of the two index types, not the source's, so for a
64-bit source into a 32-bit destination the length is i32 while the
interpreter reads it as i64. `TypeChecker::OnMemoryCopy`/`OnTableCopy`
already spell out the min rule; the runtime side just didn't follow it.
Debug builds trip the type assertion. In release the read only gives the
right answer because the `Value` union happens to be zero-initialised.
Pop the length as u64 only when both memories/tables are 64-bit.
Same-width copies are byte-identical. Regression test added under
test/interp.1 parent 11602da commit 0ef5bd9
2 files changed
Lines changed: 46 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2326 | 2326 | | |
2327 | 2327 | | |
2328 | 2328 | | |
2329 | | - | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
2330 | 2334 | | |
2331 | 2335 | | |
2332 | 2336 | | |
| |||
2364 | 2368 | | |
2365 | 2369 | | |
2366 | 2370 | | |
2367 | | - | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
2368 | 2376 | | |
2369 | 2377 | | |
2370 | 2378 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
0 commit comments