diff options
author | Alon Zakai <azakai@google.com> | 2022-01-05 08:37:04 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-05 08:37:04 -0800 |
commit | 1beec37f483505db0c5152be9118b28e45b77316 (patch) | |
tree | c94a17d10ec86907be7a938b495757989fcc4929 | |
parent | d4da7d0e593d906fc8ca05a2bb767d9f6c432c00 (diff) | |
download | binaryen-1beec37f483505db0c5152be9118b28e45b77316.tar.gz binaryen-1beec37f483505db0c5152be9118b28e45b77316.tar.bz2 binaryen-1beec37f483505db0c5152be9118b28e45b77316.zip |
Add binary format parse check for imported function types (#4423)
Without this we hit an assertion later, which is less clear.
See #4413
-rw-r--r-- | src/wasm/wasm-binary.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 57a2bc95c..95658cbe7 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2057,7 +2057,13 @@ void WasmBinaryBuilder::readImports() { Name name(std::string("fimport$") + std::to_string(functionCounter++)); auto index = getU32LEB(); functionTypes.push_back(getTypeByIndex(index)); - auto curr = builder.makeFunction(name, getTypeByIndex(index), {}); + auto type = getTypeByIndex(index); + if (!type.isSignature()) { + throwError(std::string("Imported function ") + module.str + '.' + + base.str + + "'s type must be a signature. Given: " + type.toString()); + } + auto curr = builder.makeFunction(name, type, {}); curr->module = module; curr->base = base; functionImports.push_back(curr.get()); |