From ed305017be70aaa49efa704b341001bba4ad39ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Tro=C3=9Fbach?= Date: Sat, 12 Sep 2026 07:39:39 +0200 Subject: [PATCH] Fix WASM entropy source when HEAPU8 is not exported The Emscripten variant of entropy() accessed the WebAssembly memory through Module.HEAPU8. Current Emscripten versions no longer export HEAPU8 on the Module object by default, so the access failed, entropy() returned no data and chacha20_rng() aborted on its first use, for example when writing a database encrypted with the default cipher scheme. Use the HEAPU8 view directly. It is always in scope for EM_JS code and is kept up to date when the memory grows. --- src/chacha20poly1305.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chacha20poly1305.c b/src/chacha20poly1305.c index 5ae29e42..c5a75e9a 100644 --- a/src/chacha20poly1305.c +++ b/src/chacha20poly1305.c @@ -336,7 +336,7 @@ EM_JS(int, wasm_crypto_getrandom, (uint8_t* buf, size_t n), return -1; try { - var view = new Uint8Array(Module.HEAPU8.buffer, buf, n); + var view = new Uint8Array(HEAPU8.buffer, buf, n); var chunk = 65536; for (var i = 0; i < n; i += chunk) {