Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using invalidated Wasm memory #2047

Merged
merged 2 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion wasm-node/javascript/src/internals/local-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading