summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-01-07 11:15:41 -0800
committerGitHub <noreply@github.com>2022-01-07 11:15:41 -0800
commitce8750b7a6b129849a38141f730a25bcbc3712e8 (patch)
tree8afc5565f17e3372980b1fded9a08d73746d91d6 /src/wasm/wasm-binary.cpp
parent260b8ee7f2b4f5fb87e72e99b9543eb524d12c7d (diff)
downloadbinaryen-ce8750b7a6b129849a38141f730a25bcbc3712e8.tar.gz
binaryen-ce8750b7a6b129849a38141f730a25bcbc3712e8.tar.bz2
binaryen-ce8750b7a6b129849a38141f730a25bcbc3712e8.zip
Warn about and ignore empty local/param names in name section (#4426)
Fixes the crash in #4418 Also replace the .at() there with better logic to handle imported functions. See WebAssembly/wabt#1799 for details on why wabt sometimes emits this.
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 4804626da..5ebc4d864 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -749,8 +749,18 @@ void WasmBinaryWriter::writeNames() {
o << U32LEB(localsWithNames.size());
for (auto& [indexInFunc, name] : localsWithNames) {
// TODO: handle multivalue
- auto indexInBinary =
- funcMappedLocals.at(func->name)[{indexInFunc, 0}];
+ Index indexInBinary;
+ auto iter = funcMappedLocals.find(func->name);
+ if (iter != funcMappedLocals.end()) {
+ indexInBinary = iter->second[{indexInFunc, 0}];
+ } else {
+ // No data on funcMappedLocals. That is only possible if we are an
+ // imported function, where there are no locals to map, and in that
+ // case the index is unchanged anyhow: parameters always have the
+ // same index, they are not mapped in any way.
+ assert(func->imported());
+ indexInBinary = indexInFunc;
+ }
o << U32LEB(indexInBinary);
writeEscapedName(name.str);
}
@@ -3092,7 +3102,11 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
continue; // read and discard in case of prior error
}
auto localName = processor.process(rawLocalName);
- if (localIndex < func->getNumLocals()) {
+ if (localName.size() == 0) {
+ std::cerr << "warning: empty local name at index "
+ << std::to_string(localIndex) << " in function "
+ << std::string(func->name.str) << std::endl;
+ } else if (localIndex < func->getNumLocals()) {
func->localNames[localIndex] = localName;
} else {
std::cerr << "warning: local index out of bounds in name "