Index: lib/Object/WasmObjectFile.cpp =================================================================== --- lib/Object/WasmObjectFile.cpp +++ lib/Object/WasmObjectFile.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" @@ -268,6 +269,8 @@ } Error WasmObjectFile::parseNameSection(const uint8_t *Ptr, const uint8_t *End) { + llvm::DenseSet Seen; + while (Ptr < End) { uint8_t Type = readVarint7(Ptr); uint32_t Size = readVaruint32(Ptr); @@ -277,6 +280,9 @@ uint32_t Count = readVaruint32(Ptr); while (Count--) { uint32_t Index = readVaruint32(Ptr); + if (!Seen.insert(Index).second) + return make_error("Function named more than once", + object_error::parse_failed); StringRef Name = readString(Ptr); if (!Name.empty()) Symbols.emplace_back(Name, @@ -375,7 +381,6 @@ uint32_t Count = readVaruint32(Ptr); while (Count--) { StringRef Symbol = readString(Ptr); - DEBUG(dbgs() << "reading syminfo: " << Symbol << "\n"); uint32_t Flags = readVaruint32(Ptr); auto iter = SymbolMap.find(Symbol); if (iter == SymbolMap.end()) { Index: test/Object/wasm-duplicate-name.test =================================================================== --- /dev/null +++ test/Object/wasm-duplicate-name.test @@ -0,0 +1,28 @@ +# RUN: yaml2obj %s | not llvm-objdump -h - 2>&1 | FileCheck %s + +--- !WASM +FileHeader: + Version: 0x00000001 +Sections: + - Type: TYPE + Signatures: + - Index: 0 + ReturnType: I32 + ParamTypes: + - I32 + - Type: IMPORT + Imports: + - Module: foo + Field: a + Kind: FUNCTION + SigIndex: 0 + - Type: CUSTOM + Name: name + FunctionNames: + - Index: 0 + Name: a + - Index: 0 + Name: b +... + +# CHECK: {{.*}}: Function named more than once