Description
Hi,
In sodium-native we have a special malloc that allows you to allocated a mmap'ed buffer with special flags that provide extra protection. The signature is sodium_malloc(bytes)
where bytes
can be up to 0xffffffff
. Until Node 14 napi_get_value_uint32
would fail for numbers outside this range (eg. -1
or Number.MAX_SAFE_INTEGER
) but for Node 14 our tests now fail with varying errors on different operating system. My guess is that in Node 14, this wraps around, but it is unspecified by the napi docs whether wrap around does happen, so we might have relied on undefined behaviour.
Here is our failing tests:
https://github.com/sodium-friends/sodium-native/blob/91e28b44648164ba8054f22e9a96c826329462bd/test/memory.js#L117-L125
Here is the macro we use to read a uint32_t
from a Number
:
https://github.com/sodium-friends/sodium-native/blob/91e28b44648164ba8054f22e9a96c826329462bd/macros.h#L157-L161