]> Cypherpunks repositories - gostls13.git/commitdiff
bytes: explode checks for n too large
authorPhilippe Antoine <contact@catenacyber.fr>
Fri, 15 Apr 2022 11:36:32 +0000 (11:36 +0000)
committerGopher Robot <gobot@golang.org>
Sat, 16 Apr 2022 02:01:19 +0000 (02:01 +0000)
As is already done in strings package.

Change-Id: Ia45e6443ddf6beac5e70a1cc493119030e173139
GitHub-Last-Rev: 1174c250350f31eced1513169d62a8a3e679dcf6
GitHub-Pull-Request: golang/go#52348
Reviewed-on: https://go-review.googlesource.com/c/go/+/400239
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/bytes/bytes.go

index 2a00ce33546b1e29f56615052a8cdf78c24545f7..659a82bcc8c95b39823c2ad53c1080caa284dbf6 100644 (file)
@@ -30,7 +30,7 @@ func Compare(a, b []byte) int {
 // explode splits s into a slice of UTF-8 sequences, one per Unicode code point (still slices of bytes),
 // up to a maximum of n byte slices. Invalid UTF-8 sequences are chopped into individual bytes.
 func explode(s []byte, n int) [][]byte {
-       if n <= 0 {
+       if n <= 0 || n > len(s) {
                n = len(s)
        }
        a := make([][]byte, n)