Skip to content

Commit 85e95e3

Browse files
authored
validate all function indexes in binary reading (#1887)
fixes bug reported in comment on e63c4a7 , #1885 (comment) , #1879 (comment)
1 parent 119525e commit 85e95e3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/wasm/wasm-binary.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,9 @@ void WasmBinaryBuilder::readSignatures() {
967967
}
968968

969969
Name WasmBinaryBuilder::getFunctionIndexName(Index i) {
970+
if (i >= wasm.functions.size()) {
971+
throwError("invalid function index");
972+
}
970973
return wasm.functions[i]->name;
971974
}
972975

@@ -1505,9 +1508,6 @@ void WasmBinaryBuilder::processFunctions() {
15051508
auto index = exportIndexes[curr];
15061509
switch (curr->kind) {
15071510
case ExternalKind::Function: {
1508-
if (index >= wasm.functions.size()) {
1509-
throwError("bad function export index");
1510-
}
15111511
curr->value = getFunctionIndexName(index);
15121512
break;
15131513
}

0 commit comments

Comments
 (0)