Skip to content

Commit

Permalink
encoding/base64: fix panic when input len is not a multiple of 4
Browse files Browse the repository at this point in the history
Fixes #3442.

R=for.go.yong, dsymonds, sougou, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/5975052
  • Loading branch information
davecheney authored and dsymonds committed Apr 3, 2012
1 parent 065db4e commit 951a97e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/pkg/encoding/base64/base64.go
Expand Up @@ -230,7 +230,12 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err error) {
if in == '=' && j >= 2 && len(src) < 4 {
// We've reached the end and there's
// padding
if len(src) == 0 && j == 2 {
// not enough padding
return n, false, CorruptInputError(len(osrc))
}
if len(src) > 0 && src[0] != '=' {
// incorrect padding
return n, false, CorruptInputError(len(osrc) - len(src) - 1)
}
dlen = j
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/encoding/base64/base64_test.go
Expand Up @@ -151,6 +151,9 @@ func TestDecodeCorrupt(t *testing.T) {
{"AAA=AAAA", 3},
{"AAAAA", 4},
{"AAAAAA", 4},
{"A=", 1},
{"AA=", 3},
{"AAAAAA=", 7},
}

for _, e := range examples {
Expand Down

0 comments on commit 951a97e

Please sign in to comment.