Skip to content

use an unsigned accumulator in base64_encode#2477

Open
metsw24-max wants to merge 2 commits into
yhirose:masterfrom
metsw24-max:base64-unsigned-accumulator
Open

use an unsigned accumulator in base64_encode#2477
metsw24-max wants to merge 2 commits into
yhirose:masterfrom
metsw24-max:base64-unsigned-accumulator

Conversation

@metsw24-max

Copy link
Copy Markdown
Contributor

base64_encode folds each input byte into a signed int and shifts it left by eight every round; once four bytes are in, the top bit is set and the next shift left-shifts a negative int, which is undefined behaviour (ubsan reports a left shift of a negative value, and the same shift recurs in the trailing six-bit fixup). the helper runs on the server's websocket accept-key path over the sha1 digest and in the basic-auth header builder, so it is reachable from request handling. making the accumulator a uint32_t removes the ub and keeps the output byte-for-byte identical, since every emitted six-bit group is masked with 0x3f and is independent of the accumulator's signedness. the added test pins the rfc 4648 vectors plus a high-byte input that keeps the top bit set across rounds.

@yhirose

yhirose commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Looks like there are quite a few errors...

@metsw24-max

Copy link
Copy Markdown
Contributor Author

Those were all the same failure: the new test calls detail::base64_encode, but in the split build split.py strips inline and moves the definition into httplib.cc, so it isn't declared in the public header. I've forward-declared it in the test the same way getaddrinfo_with_timeout already is, so it resolves in both the header-only and split builds. Confirmed both compile and the test passes locally.

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