-
Notifications
You must be signed in to change notification settings - Fork 892
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
BigUint64Array some large numbers broken in wasm32-wasi #202
Comments
Here's some more interesting code that creates the same const bytes = [0, 128, 184, 57, 247, 124, 255, 255];
let bigIntValue = BigInt(0);
for (let i = 0; i < bytes.length; i++) {
bigIntValue =
(bigIntValue << BigInt(8)) +
BigInt(bytes[bytes.length - 1 - i]);
}
const bigUint64Array = new BigUint64Array(1);
bigUint64Array[0] = bigIntValue;
console.log(bigUint64Array[0].toString()); |
I narrowed down the problem to this line in code: https://github.com/bellard/quickjs/blob/2788d71e823b522b178db3b3660ce93689534e6d/quickjs.c#L12031 Something goes wrong after the call to Google search for that function shows: #131 If I apply the fix of that issue locally, then the problem disappears: #132 |
fixed |
@bellard: thanks a lot for pushing the fix. There are other occurrences of Do you think those places are safe or should also be fixed? |
Normally there is a check before. Adding unnecessary tests is expensive and should be avoided. |
Unclear why sending a SIGQUIT signal sometimes works and sometimes doesn't but it's probably some kind of race condition in Cygwin's emulation layer. Fixes: quickjs-ng/quickjs#184
Here's a very simple reproducible piece of code that shows the issue:
Some large numbers relatively close to the maximum size of an unsigned 64 bit integer (2^64 - 1 or 18_446_744_073_709_551_615) are not able to be put into the
new BigUint64Array
constructor. The resultingBigUint64Array
has a number that is not the same as the number being passed into the constructor.The code above returns the correct number
18446600000000000000n
on Node.js, Chrome, QuickJS compiled to my Ubuntu machine, Javy running on my Ubuntu machine, and rquickjs running on my Linux machine. Javy compiled to wasm32-wasi and rquickjs compiled to wasm32-wasi both return the incorrect number18446740737488355328n
. I've used bothwasmtime
andwasmer
to test that the incorrect number is returned.Other numbers are broken as well.
The text was updated successfully, but these errors were encountered: