From a9e446b5cdb2e2ffc1c54b385b7eee5d41b53dd3 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 21 Nov 2019 10:51:04 +0100 Subject: [PATCH] fix(runtime-core) Fix a panic when generating globals. Fix https://github.com/wasmerio/wasmer/issues/979. When we try to get a global that doesn't exist, a panic is generated. This patch just skip that path, and let a proper error be generated later. With this patch, we get: ```sh $ cargo run -- run panic_index_oob_all_backends.wasm Error: ExportNotFound { name: "main" } ``` which is kind of the expected behavior in such situation. --- lib/runtime-core/src/backing.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/runtime-core/src/backing.rs b/lib/runtime-core/src/backing.rs index c88cb953d..c3118cfb0 100644 --- a/lib/runtime-core/src/backing.rs +++ b/lib/runtime-core/src/backing.rs @@ -450,6 +450,11 @@ impl LocalBacking { let value = match &global_init.init { Initializer::Const(value) => value.clone(), Initializer::GetGlobal(import_global_index) => { + // Skip if the global hasn't been initialized properly. + if imports.globals.len() <= import_global_index.index() { + continue; + } + imports.globals[*import_global_index].get() } };