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

Fixed correct operation when input is negative #39

Merged
merged 1 commit into from Feb 16, 2018

Conversation

Raniz85
Copy link
Contributor

@Raniz85 Raniz85 commented Aug 24, 2017

The two integers -1 and 255 represent the same byte (0xFF),
but the code would handle -1 incorrectly because input numbers
weren't properly masked so negative integers would case the
combining step in encodeChunk to produce the wrong triplet.

As an example, the triplet [0, -73, 23] - [0x00, 0xB7, 0x17])
would combine into the integer -18665 (0xFFFFB717) instead of
the expected 46871 (0x0000B717).

This is fixed by correctly masking input values before combining
them into an integer.

This fixes #38

The two integers -1 and 255 represent the same byte (0xFF),
but the code would handle -1 incorrectly because input numbers
weren't properly masked so negative integers would case the
combining step in encodeChunk to produce the wrong triplet.

As an example, the triplet [0, -73, 23]  - [0x00, 0xB7, 0x17])
would combine into the integer -18665 (0xFFFFB717) instead of
the expected 46871 (0x0000B717).

This is fixed by correctly masking input values before combining
them into an integer.
@feross feross merged commit 4002c65 into beatgammit:master Feb 16, 2018
@feross
Copy link
Collaborator

feross commented Feb 16, 2018

Sorry for the delay. I just confirmed your fix, merged, and released as 1.2.2.

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.

Negative numbers in input produce wrong results
2 participants