Skip to content

Commit 9498d5e

Browse files
authored
[Parser] Avoid an internal assertion when a function's type does not match params (WebAssembly#7247)
The parser trusted the type when calling `setLocalName`, but that method asserts of the local index is invalid. Avoid that assertion so we reach the proper error message later.
1 parent 30b7241 commit 9498d5e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/parser/contexts.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,10 @@ struct ParseModuleTypesCtx : TypeParserCtx<ParseModuleTypesCtx>,
13251325
return in.err(pos, "expected signature type");
13261326
}
13271327
f->type = type.type;
1328-
for (Index i = 0; i < type.names.size(); ++i) {
1328+
// If we are provided with too many names (more than the function has), we
1329+
// will error on that later when we check the signature matches the type.
1330+
// For now, avoid asserting in setLocalName.
1331+
for (Index i = 0; i < std::min(type.names.size(), f->getNumLocals()); ++i) {
13291332
if (type.names[i].is()) {
13301333
f->setLocalName(i, type.names[i]);
13311334
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
;; This function's type does not match the param we define for it.
2+
3+
;; RUN: not wasm-opt %s 2>&1 | filecheck %s
4+
;; CHECK: Fatal: 9:10: error: type does not match provided signature
5+
6+
(module
7+
(type $0 (func))
8+
9+
(func $0 (type $0) (param $var$0 i32))
10+
)

0 commit comments

Comments
 (0)