You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stdlib(encoding): to_base64 is wrong for non-ASCII input on Bun-ESM (UTF-16 units, not UTF-8 octets) — silent wrong output #849
On Bun-ESM, encoding::to_base64 returns wrong output for any string containing non-ASCII characters. This is silent wrong output, the top tier (T0) on #563.
stdlib/encoding.affine reads the input through len / string_sub / string_char_code_at. These index by UTF-8 octet on the interpreter and core wasm, but by UTF-16 code unit on Bun-ESM (#831). On Bun the encoder therefore encodes UTF-16 code units, truncated to bytes, instead of the UTF-8 octets. No existing test applies these functions to a non-ASCII string, which is why it went unnoticed.
Other byte-oriented stdlib code has the same shape and is likely affected the same way: hex helpers in stdlib/SafeHex.affine and JSON escaping in stdlib/json.affine. Those were not run.
Not verified here
The #831 investigation reported that core wasm returns the correct w6k= and 8J+mnA==. I could not reproduce that path standalone: a stdlib module imported into a standalone wasm build is an unresolved import. The interpreter currently fails on this program's let mut loop, which PR #843 fixes.
Problem: On Bun-ESM, encoding::to_base64 silently returns wrong output for non-ASCII input (é gives 6Q==, 🦜 gives P5w=). len / string_sub / string_char_code_at index by UTF-16 code unit there (#831), so the encoder encodes truncated UTF-16 units instead of UTF-8 octets. Expected: RFC 4648 output of the UTF-8 octets on every backend (w6k=, 8J+mnA==), matching printf ... | base64. Missing: Bun version used, confirmation on core wasm and on the interpreter once #843 lands, whether SafeHex.affine and json.affine are actually affected
Activity
whatproblem-ai commentedon Dec 1, 2026
Problem: On Bun-ESM,
encoding::to_base64silently returns wrong output for non-ASCII input (égives6Q==,🦜givesP5w=).len/string_sub/string_char_code_atindex by UTF-16 code unit there (#831), so the encoder encodes truncated UTF-16 units instead of UTF-8 octets.Expected: RFC 4648 output of the UTF-8 octets on every backend (
w6k=,8J+mnA==), matchingprintf ... | base64.Missing: Bun version used, confirmation on core wasm and on the interpreter once #843 lands, whether
SafeHex.affineandjson.affineare actually affectedClarity: 93%. Clear enough to work on.
⌨️ Commands · 💬 Have feedback? Tell us · 🎯 New here? Add WhatProblem to your repo · 🔒 Privacy