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: RawStdEncoding DecodedLen off by 1 for lengths not divisible by 3 #16687

Closed
xirafa opened this issue Aug 13, 2016 · 3 comments
Closed

Comments

@xirafa
Copy link

xirafa commented Aug 13, 2016

  1. What version of Go are you using (go version)?
    go version go1.6.2 windows/amd64
  2. What operating system and processor architecture are you using (go env)?
    set GOARCH=amd64
    set GOBIN=
    set GOEXE=.exe
    set GOHOSTARCH=amd64
    set GOHOSTOS=windows
    set GOOS=windows
    set GOPATH=c:\dev\go
    set GORACE=
    set GOROOT=C:\Go
    set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
    set GO15VENDOREXPERIMENT=1
    set CC=gcc
    set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
    set CXX=g++
    set CGO_ENABLED=1
  3. What did you do?
    Test decodeLen(encodedLen(x)) != x for various values of x. Only multiples of 3 produce consistent results.

See https://play.golang.org/p/l7lcBKVxDU

It is probably mistaken, e.g.:
encodedLen(1) => 2, ok since you must have 2 6-bit units to accomodate 8 bytes.
decodedLen(2) => should be 1; since you cannot extract 2 full bytes from 12 bits. In actuality, DecodedLen() returns 2.

Correcting this behavior may be bad for backward compatibility.
I suggest alternately to amend the documentation.

@xirafa xirafa changed the title RawStdEncoding DecodedLen off by 1 RawStdEncoding DecodedLen off by 1 for lengths not divisible by 3 Aug 13, 2016
@josharian josharian changed the title RawStdEncoding DecodedLen off by 1 for lengths not divisible by 3 encoding/base64: RawStdEncoding DecodedLen off by 1 for lengths not divisible by 3 Aug 13, 2016
@josharian josharian self-assigned this Aug 13, 2016
@gopherbot
Copy link

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

@cespare
Copy link
Contributor

cespare commented Aug 14, 2016

This is a duplicate of #14803, which was fixed in 87151c8.

That is, this is fixed in Go 1.7, which should be released shortly.

@josharian
Copy link
Contributor

Thanks, @cespare :)

@golang golang locked and limited conversation to collaborators Aug 14, 2017
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

4 participants