summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2020-03-16 14:42:11 -0700
committerGitHub <noreply@github.com>2020-03-16 14:42:11 -0700
commit38a795c48e269b92a1e6c54682a436ce23339a8d (patch)
tree24a34c78da288c2208843ccf69a57f4c8c6dca64
parent83d69b30b56fdc9966c84082092fe25830472dd1 (diff)
downloadbinaryen-38a795c48e269b92a1e6c54682a436ce23339a8d.tar.gz
binaryen-38a795c48e269b92a1e6c54682a436ce23339a8d.tar.bz2
binaryen-38a795c48e269b92a1e6c54682a436ce23339a8d.zip
Fix binary emitting of signature indices (#2694)
It should be a signed LEB128, not an unsigned LEB128. This bug was causing modules to be invalid when the number of signatures in the type section was large and multivalue blocks were present.
-rw-r--r--src/wasm/wasm-binary.cpp3
-rw-r--r--src/wasm/wasm-stack.cpp2
2 files changed, 4 insertions, 1 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 2b8c06c0b..9fe046c27 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1090,6 +1090,9 @@ Type WasmBinaryBuilder::getType() {
// Single value types are negative; signature indices are non-negative
if (type >= 0) {
// TODO: Handle block input types properly
+ if (size_t(type) >= signatures.size()) {
+ throwError("invalid signature index: " + std::to_string(type));
+ }
return signatures[type].results;
}
switch (type) {
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index df9ad8620..3c162a9d5 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -23,7 +23,7 @@ void BinaryInstWriter::emitResultType(Type type) {
if (type == Type::unreachable) {
o << binaryType(Type::none);
} else if (type.isMulti()) {
- o << U32LEB(parent.getTypeIndex(Signature(Type::none, type)));
+ o << S32LEB(parent.getTypeIndex(Signature(Type::none, type)));
} else {
o << binaryType(type);
}