Skip to content

Integer overflow in DataInterface.js #42

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

Open
ZoranRavic opened this issue Jan 5, 2025 · 0 comments
Open

Integer overflow in DataInterface.js #42

ZoranRavic opened this issue Jan 5, 2025 · 0 comments

Comments

@ZoranRavic
Copy link

The forceReadVint() function doesn't make sense.

You have (result << 32) | getUint32() which doesn't make sense in javascript, since binary operations work on 31-bit signed integers.

This is because js uses 32-bit integers where 1 bit is reserved.

Also in javascript doing my_int << 32 actually returns my_int, as if you didn't do anything.
This is sometimes used to convert float to int, where doing 5.67 << 32 would return 5.

Note that (result << 16) | getUint16() also wont work, because it would require a 32-bit unsigned integer (16 bits for current result value and another 16 bits that you are adding), which you don't have.

I'm guessing you copied this code from a language that had support for 64-bit integers.

You can make it work by replacing << with multiplication and | with addition, which would treat the number as a double float.
This wont give you a full 64-bit int, but that shouldn't matter. Alternative would be to use BigInt.

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

No branches or pull requests

1 participant