llrt icon indicating copy to clipboard operation
llrt copied to clipboard

Buffer.from(str, 'base64') fails to decode valid Base64

Open dforsber opened this issue 2 years ago • 4 comments

I wanted to try out LLRT, but I failed to get base64 decoding to work.

Buffer.from(str, 'base64');

dforsber avatar Feb 09 '24 17:02 dforsber

Hi there. Thanks for the issue. Do you have an example string?

richarddd avatar Feb 09 '24 18:02 richarddd

Hey there, I've been browsing this project as I work with AWS daily, excited to see where it goes! Took some time to investigate this myself to see if I could reproduce the issue. The only time I was able to produce an error was when decoding a Buffer into ascii, but this seems like it's probably intended behavior.

@dforsber Here's an example project that will get you started with a zip file that you can deploy to AWS. Here's the output you should expect when you test the lambda:

image

Please note: you will need to provide your own llrt binary for security purposes

Dgarc359 avatar Feb 10 '24 06:02 Dgarc359

Welcome to Node.js v18.18.2.
Type ".help" for more information.
> Buffer.from('eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6IlRhcFRva2VuIn0', 'base64').toString()
'{"alg":"HS512","typ":"JWT","kid":"TapToken"}'
./llrt -e 'Buffer.from("eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6IlRhcFRva2VuIn0", "base64").toString()'
Error: Base64Error
    at <eval> (eval_script:1:8)

==> It seems I need to add = to the end.

 ./llrt -e 'console.log(Buffer.from("eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6IlRhcFRva2VuIn0=", "base64").toString())'
{"alg":"HS512","typ":"JWT","kid":"TapToken"}

dforsber avatar Feb 10 '24 11:02 dforsber

Ah right, thank you. This is a padding issue. Will fix 👌

richarddavison avatar Feb 10 '24 11:02 richarddavison