diff options
author | Rikito Taniguchi <rikiriki1238@gmail.com> | 2024-06-04 04:42:02 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-03 19:42:02 +0000 |
commit | 9347a223fcc1b6c297805b3c37fe1e7473158720 (patch) | |
tree | 45d356a79b828c5ff948626a7cb7bd1c2654e128 /src/wasm/wasm-binary.cpp | |
parent | 1f2cd4f7b51c7afd6a6cafc4e48286e850bb36bd (diff) | |
download | binaryen-9347a223fcc1b6c297805b3c37fe1e7473158720.tar.gz binaryen-9347a223fcc1b6c297805b3c37fe1e7473158720.tar.bz2 binaryen-9347a223fcc1b6c297805b3c37fe1e7473158720.zip |
Fix binary parser of declarative element segments (#6618)
The parser was incorrectly handling the parsing of declarative element segments whose `init` is a `vec(expr)`.
https://webassembly.github.io/spec/core/binary/modules.html#element-section
Binry parser was simply reading a single `u32LEB` value for `init`
instead of parsing a expression regardless `usesExpressions = true`.
This commit updates the `WasmBinaryReader::readElementSegments` function
to correctly parse the expressions for declarative element segments by
calling `readExpression` instead of `getU32LEB` when `usesExpressions = true`.
Resolves the parsing exception:
"[parse exception: bad section size, started at ... not being equal to new position ...]"
Related discussion: https://github.com/tanishiking/scala-wasm/issues/136
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 805af1892..32dcc883a 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -3369,7 +3369,11 @@ void WasmBinaryReader::readElementSegments() { [[maybe_unused]] auto type = getU32LEB(); auto num = getU32LEB(); for (Index i = 0; i < num; i++) { - getU32LEB(); + if (usesExpressions) { + readExpression(); + } else { + getU32LEB(); + } } continue; } |