-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Buffer#toString unexpected / incorrect results with encoding #455
Comments
when parsing the encoding type for interestingly, there's something happening in the allocation function. i'm not sure how Zig allocators work yet but the documentation states that items are set to undefined. however, in this case i see it spits with actual values. even for a simple test case you'll see an output of arbitrary value:
|
Maybe related, something else I discovered investigating #1184 Calling toString with In Node: Buffer.from('{"alg":"RS256","typ":"JWT"}', 'latin1').toString('latin1') // '{"alg":"RS256","typ":"JWT"}' In Bun: Buffer.from('{"alg":"RS256","typ":"JWT"}', 'latin1').toString('latin1') // '≻污≧∺卒㔲∶∬祴≰∺坊≔}' It looks like the Buffer's Uint8Array is the same in both Bun and Node, so the problem is just in the conversion to string. |
@binary-koan you are describing #1016 . It works in 0.1.5 but regressed afterwards. Using 0.1.5 on Intel Mac: % curl -LO https://github.com/oven-sh/bun/releases/download/bun-v0.1.5/bun-darwin-x64.zip
% unzip bun-darwin-x64.zip
% cat <<EOF > t.js
console.log(Buffer.from('{"alg":"RS256","typ":"JWT"}', 'latin1').toString('latin1'))
EOF
% ./bun-darwin-x64/bun --version; ./bun-darwin-x64/bun t.js
0.1.5
{"alg":"RS256","typ":"JWT"} Trying the same with 0.1.6: % curl -LO https://github.com/oven-sh/bun/releases/download/bun-v0.1.6/bun-darwin-x64.zip
% unzip bun-darwin-x64.zip
% cat <<EOF > t.js
console.log(Buffer.from('{"alg":"RS256","typ":"JWT"}', 'latin1').toString('latin1'))
EOF
% ./bun-darwin-x64/bun --version; ./bun-darwin-x64/bun t.js
0.1.6
≻污≧∺卒㔲∶∬祴≰∺坊≔}Р찜˵ |
looks like Zig in safe mode intentionally sets values to An ideal solution would be to zero out or set custom type before sending it to JSC so it ignores it. |
Can you try again with the latest Bun, @SheetJSDev ? Both of your examples work for me in both Bun |
Digging into https://github.com/Jarred-Sumner/bun/issues/406 , one issue pertained to Buffer semantics. SheetJS assumes NodeJS documented
Buffer
behavior intoString
. Bun diverges in a few ways:A)
utf16le
spurious data. The UTF16LE representation of the ASCII characterA
is[ 0x41, 0 ]
.NodeJS prints the expected
[ 65 ]
(one character,0x41 == 65
) but Bun generates two characters[ 65, 209 ]
B)
base64
encoding does not include padding:As noted in the NodeJS docs,
base64url
omits padding whilebase64
includes padding.The text was updated successfully, but these errors were encountered: