diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp index 403add53619..8505d31f005 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp @@ -206,6 +206,8 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector()) auxiliary_instance.globals().append(*ptr); + else if (auto* ptr = entry.get_pointer()) + auxiliary_instance.functions().append(*ptr); } Vector module_functions; @@ -253,7 +255,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector {}, entry, entry.instructions().size(), @@ -306,7 +308,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector {}, active_ptr->expression, 1, @@ -361,7 +363,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector {}, data.offset, 1, diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index 1dd6d506d8d..1b229c07ec2 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -728,6 +728,9 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi } case Instructions::global_get.value(): { auto global_index = instruction.arguments().get(); + // This check here is for const expressions. In non-const expressions, + // a validation error would have been thrown. + TRAP_IF_NOT(global_index < configuration.frame().module().globals().size()); auto address = configuration.frame().module().globals()[global_index.value()]; dbgln_if(WASM_TRACE_DEBUG, "global({}) -> stack", address.value()); auto global = configuration.store().get(address);