]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] encoding/base64: fix panic when input len is not a multiple...
authorDave Cheney <dave@cheney.net>
Tue, 3 Apr 2012 02:14:02 +0000 (12:14 +1000)
committerDavid Symonds <dsymonds@golang.org>
Tue, 3 Apr 2012 02:14:02 +0000 (12:14 +1000)
««« 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

»»»

src/pkg/encoding/base64/base64.go
src/pkg/encoding/base64/base64_test.go

index 55f9f67a43a566bcd466193dc1404a4f55ee7aae..f8a51a4e7568fc8c5087718bb0057c1b5db306dc 100644 (file)
@@ -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
index 3e9a84393b60150f22eb88d0bc60342daeba82c1..9c35372598cb292220b4bdb5781cff92e636a806 100644 (file)
@@ -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 {