You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In passStringToWasm, the value returned from malloc is assumed to be positive. However, if malloc returns a pointer to memory at an address higher than 0x7fffffff (2 GB), the returned value will be negative, because JavaScript interprets the integer as unsigned. This results in out-of-bounds errors.
mkdir repro-wasm-bindgen-2gb-limit &&cd repro-wasm-bindgen-2gb-limit
curl -L https://github.com/rustwasm/wasm-bindgen/files/10749253/repro.tar.gz | tar xv
wasm-pack build --target nodejs
node test.cjs
test.cjs:
constwasm=require('./pkg/tmp2')wasm.allocate(1*1024*1024*1024)console.log(wasm.give_me_strings('aoeu'))// Prints 97wasm.allocate(1*1024*1024*1024-1024*1024)console.log(wasm.give_me_strings('aoeu'))// Prints 0
Describe the Bug
In
passStringToWasm
, the value returned frommalloc
is assumed to be positive. However, ifmalloc
returns a pointer to memory at an address higher than 0x7fffffff (2 GB), the returned value will be negative, because JavaScript interprets the integer as unsigned. This results in out-of-bounds errors.Steps to Reproduce
Self-contained repro: repro.tar.gz
test.cjs:
Expected Behavior
give_me_strings
should print97
both timesActual Behavior
Additional Context
Relevant blog post: https://v8.dev/blog/4gb-wasm-memory
Editing the
passStringToWasm0
binding code to run themalloc
return value through>>> 0
to force it to be unsigned fixes the issue.The text was updated successfully, but these errors were encountered: