Skip to content

symbol: Fix base64_encode to correctly encode bytes above 0x7F #311

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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lewissbaker
Copy link

Fix a bug in base64_encode() function that was incorrectly encoding bytes with the most-significant bit set in the second or third byte of a 3-byte group.

This was due to the use of signed char types in the bit-shifting expressions resulting in signed-extension causing all of the bits of the previous bytes to be overwritten with 1's.

This fixes the problem by first casting the values to unsigned char so that the bit-shift, which promotes the type to int, does not do signed-integer extension.

This fixes the problem by first casting the values to unsigned char so that the bit-shift, which promotes the type to int, does not do signed-integer extension.

Fixes #310

Fix a bug in base64_encode() function that was incorrectly encoding
bytes with the most-significant bit set in the second or third byte of
a 3-byte group.

This was due to the use of signed `char` types in the bit-shifting
expressions resulting in signed-extension causing all of the bits of the
previous bytes to be overwritten with 1's.

This fixes the problem by first casting the values to `unsigned char` so
that the bit-shift, which promotes the type to `int`, does not do
signed-integer extension.

This fixes the problem by first casting the values to `unsigned char` so that the bit-shift, which promotes the type to `int`, does not do signed-integer extension.

Signed-off-by: Lewis Baker <[email protected]>
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.

XML output incorrectly base64-encodes binary data
1 participant