Skip to content
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

Error Writing file with file size >2GB #5

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

roycwc
Copy link

@roycwc roycwc commented Sep 24, 2024

Normal case var value = 2147450880:

$ node
Welcome to Node.js v20.17.0.
Type ".help" for more information.
> var value = 2147450880
undefined
> var hi = (value / 0x100000000) | 0;
undefined
> var lo = (value & 0xffffffff) | 0;
undefined
> hi
0
> lo
2147450880

lo is still positive

Error case var value2 = 2147659776:

> var value2 = 2147659776
undefined
> var hi2 = (value2 / 0x100000000) | 0;
undefined
> var lo2 = (value2 & 0xffffffff) | 0;
undefined
> hi2
0
> lo2
-2147307520

lo2 becomes -2147307520 indicate an overflow

This fix use js native buffer.writeBigUInt64BE and buffer.readBigUInt64BE to write js Number into a 64 bit buffer

@williamstein
Copy link
Contributor

Wow, I strongly agree. Thanks!

@williamstein williamstein merged commit 7a7dcb9 into sagemathinc:main Sep 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants