From 5e4543c29ff930084f79cd982d6eee0f13f52565 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Fri, 15 Apr 2022 11:36:32 +0000 Subject: [PATCH] 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 --- src/bytes/bytes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) -- 2.48.1