Skip to content

Conversation

@yurydelendik
Copy link
Contributor

The static std::string base64Encode(std::vector<char> &data) { uses signed char in input data. The ((int)data[0]) converts it the signed int, making '\xFF' char into -1. The patch fixes casting.

@yurydelendik yurydelendik changed the title Fix base64 encoding [wasmjs] Fix base64 encoding Sep 5, 2018
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

How about using uint8_t instead of unsigned? Also might as well change base64Encode to receive a vector of those.

Please also add a test.

@yurydelendik
Copy link
Contributor Author

How about using uint8_t instead of unsigned?

Fixed

Also might as well change base64Encode to receive a vector of those.

This change goes all the way to Module -- maybe different patch.

Please also add a test.

Done

@yurydelendik yurydelendik changed the title [wasmjs] Fix base64 encoding [wasm2js] Fix base64 encoding Sep 5, 2018
src/wasm2js.h Outdated
(((int) data[i + 0]) << 16) |
(((int) data[i + 1]) << 8) |
(((int) data[i + 2]) << 0);
(((uint8_t) data[i + 0]) << 16) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, wait, this doesn't seem right - as uint8_t it would just be 0 after doing << 16, wouldn't it? I think we want uint32_t here.

Please also make sure we have a test that verifies that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the attached test verifies just that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the (uint8_t) cast is needed to fix the bug. the "the integer promotions" extends it to integer. I can be explicit and add (uint32_t) everywhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks, I think it's less surprising to read that way. lgtm.

@yurydelendik yurydelendik merged commit f831369 into WebAssembly:master Sep 5, 2018
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