Skip to content

Commit

Permalink
Add binary format parse checking for ref.as input type (#4389)
Browse files Browse the repository at this point in the history
If that type is not valid then we cannot even create and finalize the node,
which means we'd hit an assertion inside finalize(), before we reach the
validator.

Fixes #4383
  • Loading branch information
kripken committed Dec 16, 2021
1 parent 4905e74 commit 62d83d5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6898,6 +6898,9 @@ void WasmBinaryBuilder::visitRefAs(RefAs* curr, uint8_t code) {
WASM_UNREACHABLE("invalid code for ref.as_*");
}
curr->value = popNonVoidExpression();
if (!curr->value->type.isRef() && curr->value->type != Type::unreachable) {
throwError("bad input type for ref.as: " + curr->value->type.toString());
}
curr->finalize();
}

Expand Down
6 changes: 6 additions & 0 deletions test/lit/binary/bad-ref-as.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;; Test that we error properly on a file with a ref.as of a non-ref type.

;; RUN: not wasm-opt %s.wasm 2>&1 | filecheck %s

;; CHECK: parse exception: bad input type for ref.as: i32

Binary file added test/lit/binary/bad-ref-as.test.wasm
Binary file not shown.

0 comments on commit 62d83d5

Please sign in to comment.