diff options
author | Dave Cheney <dave@cheney.net> | 2012-04-03 12:14:02 +1000 |
---|---|---|
committer | David Symonds <dsymonds@golang.org> | 2012-04-03 12:14:02 +1000 |
commit | eacdcccb9efcc5d9bd76329c7bcc8328244e6f31 (patch) | |
tree | 81acabf8af49dee989ee2411b0db28678818cff5 | |
parent | efcd0d5bd82a9fd7d3847b459d61b67f962437c9 (diff) | |
download | go-eacdcccb9efcc5d9bd76329c7bcc8328244e6f31.tar.gz go-eacdcccb9efcc5d9bd76329c7bcc8328244e6f31.zip |
[release-branch.go1] encoding/base64: fix panic when input len is not a multiple of 4
««« backport 95e67cc5fa08
encoding/base64: fix panic when input len is not a multiple of 4
Fixes #3442.
R=for.go.yong, dsymonds, sougou, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/5975052
»»»
-rw-r--r-- | src/pkg/encoding/base64/base64.go | 5 | ||||
-rw-r--r-- | src/pkg/encoding/base64/base64_test.go | 3 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/pkg/encoding/base64/base64.go b/src/pkg/encoding/base64/base64.go index 55f9f67a43..f8a51a4e75 100644 --- a/src/pkg/encoding/base64/base64.go +++ b/src/pkg/encoding/base64/base64.go @@ -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 diff --git a/src/pkg/encoding/base64/base64_test.go b/src/pkg/encoding/base64/base64_test.go index 3e9a84393b..9c35372598 100644 --- a/src/pkg/encoding/base64/base64_test.go +++ b/src/pkg/encoding/base64/base64_test.go @@ -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 { |