From: Philippe Antoine Date: Fri, 15 Apr 2022 11:36:32 +0000 (+0000) Subject: bytes: explode checks for n too large X-Git-Tag: go1.19beta1~649 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5e4543c29ff930084f79cd982d6eee0f13f52565;p=gostls13.git bytes: explode checks for n too large 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 TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov --- diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go index 2a00ce3354..659a82bcc8 100644 --- a/src/bytes/bytes.go +++ b/src/bytes/bytes.go @@ -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)