From d9e05924d660a4914c29e707299865603563e7d2 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 5 Oct 2023 16:57:34 +0300 Subject: [PATCH] Fix misuse of Module Before this fix, the compiling engine was attached to the Module instance (indirectly via the artifact). However, the Store used was created from a different engine. --- packages/vm/src/cache.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/vm/src/cache.rs b/packages/vm/src/cache.rs index 070b624cf3..dd62d96c3a 100644 --- a/packages/vm/src/cache.rs +++ b/packages/vm/src/cache.rs @@ -377,11 +377,22 @@ where // stored the old module format. let wasm = self.load_wasm_with_path(&cache.wasm_path, checksum)?; cache.stats.misses = cache.stats.misses.saturating_add(1); - // Module will run with a different engine, so we can set memory limit to None - let engine = make_compiling_engine(None); - let module = compile(&engine, &wasm)?; - let module_size = cache.fs_cache.store(checksum, &module)?; + { + // Module will run with a different engine, so we can set memory limit to None + let compiling_engine = make_compiling_engine(None); + // Note that module cannot be used directly as it was not created with the + // runtime engine. + let module = compile(&compiling_engine, &wasm)?; + cache.fs_cache.store(checksum, &module)?; + } + // This time we'll hit the file-system cache. + let Some((module, module_size)) = cache.fs_cache.load(checksum, &cache.runtime_engine)? + else { + return Err(VmError::generic_err( + "Can't load module from file system cache after storing it to file system cache", + )); + }; cache .memory_cache .store(checksum, module.clone(), module_size)?;