-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
napi_get_value_uint32 difference between Node 14 and previous #33117
Comments
@emilbayes Are you sure that that is the case? The code in N-API hasn’t changed here, and it has always implemented wrap-around behavior for e.g. negative numbers (i.e. it implements |
No, we could have been doing the wrong thing all along 🤔 Just saw that it started breaking on Node 14: https://travis-ci.org/github/sodium-friends/sodium-native/builds/680466769 |
@emilbayes I checked all the way back to v10.x and |
Adds a test to ensure that napi_get_value_uint32 returns 0xffffffff for -1. Re: nodejs#33117 Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com>
Adds a test to ensure that napi_get_value_uint32 returns 0xffffffff for -1. Re: #33117 Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com>
Adds a test to ensure that napi_get_value_uint32 returns 0xffffffff for -1. Re: #33117 Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com>
@emilbayes I have added a test to ensure that the behaviour remains consistent going forward. Please re-open if you believe that the problem lies within Node.js. |
Adds a test to ensure that napi_get_value_uint32 returns 0xffffffff for -1. Re: #33117 Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com>
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)
wherebytes
can be up to0xffffffff
. Until Node 14napi_get_value_uint32
would fail for numbers outside this range (eg.-1
orNumber.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 aNumber
:https://github.com/sodium-friends/sodium-native/blob/91e28b44648164ba8054f22e9a96c826329462bd/macros.h#L157-L161
The text was updated successfully, but these errors were encountered: