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

Fix bug with ranges larger than 2**31 in buffer.toString() method #1

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

Miller-GS
Copy link
Owner

This PR is fixing the bug reported on this issue

When we create buffers larger than 2ˆ31 and try to call toString passing start and end also larger than 2ˆ31 (but still smaller than the size of the buffer), we end up with an ERR_OUT_OF_RANGE.

In this PR, we're adding a unit test to validate this scenario. Initially, this error happens:
Captura de Tela 2024-06-20 às 22 10 03

We figured out that this error is caused by the bitwise-or operation done to cast "start" and "end" to numbers. This operation only supports positive integers up to 2ˆ31. After, it will truncate and even consider them as negative numbers due to interpreting them as a 2's complement. After changing this to a MathTrunc instead, all tests passed correctly:
Captura de Tela 2024-06-20 às 22 10 41

@Miller-GS Miller-GS self-assigned this Jun 21, 2024
@Miller-GS Miller-GS merged commit eac55d8 into main Jun 21, 2024
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.

1 participant