]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] encoding/ascii85: fix panic caused by special case
authorDmitry Chestnykh <dchest@gmail.com>
Wed, 4 Apr 2012 13:52:42 +0000 (09:52 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 4 Apr 2012 13:52:42 +0000 (09:52 -0400)
««« backport b127df6df1ab
encoding/ascii85: fix panic caused by special case

Special case for encoding 4 zeros as 'z' didn't
update source slice, causing 'index out of bounds'
panic in destination slice.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5970078

»»»

src/pkg/encoding/ascii85/ascii85.go
src/pkg/encoding/ascii85/ascii85_test.go

index 7d004b5e5d74eb0c73d86de59770edf1c58d207d..705022792a863bc417179c261467db2251c48da4 100644 (file)
@@ -57,6 +57,7 @@ func Encode(dst, src []byte) int {
                if v == 0 && len(src) >= 4 {
                        dst[0] = 'z'
                        dst = dst[1:]
+                       src = src[4:]
                        n++
                        continue
                }
index 70e67d8b06e092100238ff3b7badd50a595d7bd5..42cf7e80e1b3b5ccb57080122d2fd7da9d78219d 100644 (file)
@@ -28,6 +28,11 @@ var pairs = []testpair{
                        "l(DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G\n" +
                        ">uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c\n",
        },
+       // Special case when shortening !!!!! to z.
+       {
+               "\000\000\000\000",
+               "z",
+       },
 }
 
 var bigtest = pairs[len(pairs)-1]