diff options
| author | Rui Ueyama <ruiu@google.com> | 2014-03-18 20:52:58 -0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2014-03-18 20:52:58 -0700 |
| commit | 1a21dbc5720326b0e325a54c3e01c0e50b32eb03 (patch) | |
| tree | 89850483dfa45085a0a4bcb454f01c0b3422ef14 /src/pkg/bytes/bytes.go | |
| parent | f34251a91c2d075def51b763c52a0c602f3e09c9 (diff) | |
| download | go-1a21dbc5720326b0e325a54c3e01c0e50b32eb03.tar.xz | |
bytes: fix panic in Map
utf8.RuneLen returns -1 for an invalid rune. In that case we
need to extend the internal buffer at least by 3 for \uFFFD.
Fixes #7577.
LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/77420044
Diffstat (limited to 'src/pkg/bytes/bytes.go')
| -rw-r--r-- | src/pkg/bytes/bytes.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/pkg/bytes/bytes.go b/src/pkg/bytes/bytes.go index 644bf75b89..0c53e4c0b7 100644 --- a/src/pkg/bytes/bytes.go +++ b/src/pkg/bytes/bytes.go @@ -356,7 +356,11 @@ func Map(mapping func(r rune) rune, s []byte) []byte { } r = mapping(r) if r >= 0 { - if nbytes+utf8.RuneLen(r) > maxbytes { + rl := utf8.RuneLen(r) + if rl < 0 { + rl = len(string(utf8.RuneError)) + } + if nbytes+rl > maxbytes { // Grow the buffer. maxbytes = maxbytes*2 + utf8.UTFMax nb := make([]byte, maxbytes) |
