summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-03-17 14:11:52 -0700
committerGitHub <noreply@github.com>2023-03-17 14:11:52 -0700
commit8f57b66171f6166f35f8549ea5cf7c047a2a7a28 (patch)
tree433a5c18df7b4a64872899c6d6afa0e1f8c9be1f
parent69ff3bf4f10d1f50343a3db7e4730b576f679c70 (diff)
downloadbinaryen-8f57b66171f6166f35f8549ea5cf7c047a2a7a28.tar.gz
binaryen-8f57b66171f6166f35f8549ea5cf7c047a2a7a28.tar.bz2
binaryen-8f57b66171f6166f35f8549ea5cf7c047a2a7a28.zip
[Exceptions] Fix error on bad delegate index (#5587)
Fixes #5584
-rw-r--r--src/wasm/wasm-binary.cpp7
-rw-r--r--test/lit/binary/bad-delegate.test17
-rw-r--r--test/lit/binary/bad-delegate.test.wasmbin0 -> 32 bytes
3 files changed, 23 insertions, 1 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 9368325b0..5326972b0 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -2560,7 +2560,12 @@ void WasmBinaryBuilder::readFunctions() {
assert(depth == 0);
assert(breakStack.empty());
assert(breakTargetNames.empty());
- assert(exceptionTargetNames.empty());
+ if (!exceptionTargetNames.empty()) {
+ // A delegate index existed that did not end up referring to any valid
+ // outer try-catch (we remove valid ones from exceptionTargetNames as we
+ // go).
+ throwError("exceptionTargetNames not empty - invalid delegate");
+ }
if (!expressionStack.empty()) {
throwError("stack not empty on function exit");
}
diff --git a/test/lit/binary/bad-delegate.test b/test/lit/binary/bad-delegate.test
new file mode 100644
index 000000000..8e6a011a5
--- /dev/null
+++ b/test/lit/binary/bad-delegate.test
@@ -0,0 +1,17 @@
+;; Test that we error properly on a file with a bad delegate (a delegate of an
+;; index that does not refer to a valid try-catch).
+
+;; Disassembled binary from wabt:
+;;
+;; (module
+;; (type (;0;) (func))
+;; (func (;0;) (type 0)
+;; block ;; label = @1
+;; try ;; label = @2
+;; nop
+;; delegate 0
+;; end))
+
+;; RUN: not wasm-opt -all %s.wasm 2>&1 | filecheck %s
+
+;; CHECK: exceptionTargetNames not empty - invalid delegate
diff --git a/test/lit/binary/bad-delegate.test.wasm b/test/lit/binary/bad-delegate.test.wasm
new file mode 100644
index 000000000..db9645e35
--- /dev/null
+++ b/test/lit/binary/bad-delegate.test.wasm
Binary files differ