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

encoding/base64: DecodedLen overestimates size when using NoPadding #14803

Closed
manger opened this issue Mar 13, 2016 · 2 comments
Closed

encoding/base64: DecodedLen overestimates size when using NoPadding #14803

manger opened this issue Mar 13, 2016 · 2 comments

Comments

@manger
Copy link

manger commented Mar 13, 2016

go version = 1.6
go env = windows, 386

http://play.golang.org/p/NzPTnjKUPy

The base64 encoding (without padding): of 1 bytes gives 2 chars; of 2 bytes gives 3 chars. And the reverse mapping is true (2 chars decode to 1 byte; 3 chars to 2 bytes).

base64.RawURLEncoding.DecodedLen(2) returns 2, but should return 1.
base64.RawURLEncoding.DecodedLen(3) returns 3, but should return 2.

The bug is the calculation for the NoPadding case in DecodedLen:
WRONG return (n*6 + 7) / 8
RIGHT return n*6 / 8
https://golang.org/src/encoding/base64/base64.go

@cespare
Copy link
Contributor

cespare commented Mar 14, 2016

Nice find. I mailed a fix.

@gopherbot
Copy link

CL https://golang.org/cl/20649 mentions this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants