wasi-runtime random_get is a no-op stub (returns 0, writes nothing) #22
Labels
No labels
bug
claude:done
claude:failed
claude:in-progress
claude:ready
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Catcrafts/Crafter.Build#22
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In
wasi-runtime/runtime.jsthe WASIrandom_getimport is stubbed:It returns success (
0) but never writes any bytes into the target buffer, so the destination stays whatever it was (zero in practice). Any wasm program that usesstd::random_device(or otherwise callsrandom_get) therefore gets all-zero "randomness".This bit us in 3DForts: every browser tab generated an identical all-zero peer id from
std::random_device, which collided WebRTC signaling routing (two peers can't share an id). We worked around it app-side by sourcing entropy fromcrypto.getRandomValuesvia our own JS bridge, but the runtime stub is the root cause and will silently break any otherrandom_deviceuser.Suggested fix: back
random_getwithcrypto.getRandomValues, e.g.(adjust for how the runtime accesses wasm memory / the import's arg shape). Found via Catcrafts/3DForts#50.