uint32_t StartFunction = -1;
bool HasLinkingSection = false;
wasm::WasmLinkingData LinkingData;
+ uint32_t NumImportedGlobals = 0;
+ uint32_t NumImportedFunctions = 0;
StringMap<uint32_t> SymbolMap;
};
Im.Kind = readUint8(Ptr);
switch (Im.Kind) {
case wasm::WASM_EXTERNAL_FUNCTION:
+ NumImportedFunctions++;
Im.SigIndex = readVaruint32(Ptr);
SymbolMap.try_emplace(Im.Field, Symbols.size());
Symbols.emplace_back(Im.Field, WasmSymbol::SymbolType::FUNCTION_IMPORT,
<< " sym index:" << Symbols.size() << "\n");
break;
case wasm::WASM_EXTERNAL_GLOBAL:
+ NumImportedGlobals++;
Im.Global.Type = readVarint7(Ptr);
Im.Global.Mutable = readVaruint1(Ptr);
SymbolMap.try_emplace(Im.Field, Symbols.size());
switch (Ex.Kind) {
case wasm::WASM_EXTERNAL_FUNCTION:
ExportType = WasmSymbol::SymbolType::FUNCTION_EXPORT;
+ if (Ex.Index >= FunctionTypes.size() + NumImportedFunctions)
+ return make_error<GenericBinaryError>("Invalid function export",
+ object_error::parse_failed);
MakeSymbol = true;
break;
case wasm::WASM_EXTERNAL_GLOBAL:
ExportType = WasmSymbol::SymbolType::GLOBAL_EXPORT;
+ if (Ex.Index >= Globals.size() + NumImportedGlobals)
+ return make_error<GenericBinaryError>("Invalid global export",
+ object_error::parse_failed);
MakeSymbol = true;
break;
case wasm::WASM_EXTERNAL_MEMORY: