From be1f9542ae2207fd4c379ce9b99d51b500f01cee Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sun, 24 Nov 2024 10:29:37 +0100 Subject: [PATCH 1/2] Fix using invalidated Wasm memory --- wasm-node/javascript/src/internals/local-instance.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wasm-node/javascript/src/internals/local-instance.ts b/wasm-node/javascript/src/internals/local-instance.ts index 1b601bb93f..09e8a5e2c9 100644 --- a/wasm-node/javascript/src/internals/local-instance.ts +++ b/wasm-node/javascript/src/internals/local-instance.ts @@ -509,8 +509,10 @@ export async function startLocalInstance(config: Config, wasmModule: WebAssembly if (!state.instance) return null; - const mem = new Uint8Array(state.instance.exports.memory.buffer); const responseInfo = state.instance.exports.json_rpc_responses_peek(chainId) >>> 0; + // Note that the memory must be created after calling the Wasm function, otherwise + // it might be invalidated if it is grown. + const mem = new Uint8Array(state.instance.exports.memory.buffer); const ptr = buffer.readUInt32LE(mem, responseInfo) >>> 0; const len = buffer.readUInt32LE(mem, responseInfo + 4) >>> 0; From c562fa33fad9174d5dd377256041320dbff2ef73 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sun, 24 Nov 2024 10:34:35 +0100 Subject: [PATCH 2/2] CHANGELOG --- wasm-node/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wasm-node/CHANGELOG.md b/wasm-node/CHANGELOG.md index 501ba47d62..b5106582db 100644 --- a/wasm-node/CHANGELOG.md +++ b/wasm-node/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixed + +- Fix a `RangeError` exception sometimes being thrown due the smoldot Wasm instance growing its memory at an unexpected time. ([#2047](https://github.com/smol-dot/smoldot/pull/2047)) + ## 2.0.33 - 2024-11-19 ### Fixed