Skip to content
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

Fix base64 error when input is multiple of 4 bytes #1

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

alext
Copy link
Member

@alext alext commented Oct 7, 2024

The base64Decode function was incorrectly re-adding padding when the input is a multiple of 4 bytes. These input lengths should have no padding, but it was adding 1, which led to an error:

illegal base64 data at input byte 4

The base64 package has options to omit padding using WithPadding(base64.NoPadding)[1], and also defines Raw versions of the pre-defined encoders[2]. This therefore updates the functions to use these encoders instead, which means they're now just simple wrappers.

[1]https://pkg.go.dev/encoding/base64#Encoding.WithPadding
[2]https://pkg.go.dev/encoding/base64#pkg-variables

The base64Decode function was incorrectly re-adding padding when the
input is a multiple of 4 bytes. These input lengths should have no
padding, but it was adding 1, which led to an error:

> illegal base64 data at input byte 4

The base64 package has options to omit padding using
`WithPadding(base64.NoPadding)`[1], and also defines Raw versions of the
pre-defined encoders[2]. This therefore updates the functions to use
these encoders instead, which means they're now just simple wrappers.

[1]https://pkg.go.dev/encoding/base64#Encoding.WithPadding
[2]https://pkg.go.dev/encoding/base64#pkg-variables
@alext alext merged commit 351de4d into master Oct 7, 2024
3 checks passed
@alext alext deleted the fix_base64_unpad branch October 7, 2024 09:40
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.

1 participant