From cc46cac3bc59c35e22e17471d70e28fd3705d4da Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Sun, 20 Mar 2022 21:34:42 +0000 Subject: strings: limits allocation size for SplitN So that `strings.SplitN("", "T", int(144115188075855872))` does not panic. Change-Id: Iea00417e61780bcaf0fee02fa2b18026d89bc545 GitHub-Last-Rev: d1f45b44a8011ddb27c71e1bc9983b62b5d3d771 GitHub-Pull-Request: golang/go#51755 Reviewed-on: https://go-review.googlesource.com/c/go/+/393654 Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Trust: Tobias Klauser --- src/strings/strings.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/strings/strings.go') diff --git a/src/strings/strings.go b/src/strings/strings.go index 5793d9e26f..ed3184b59c 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -244,6 +244,9 @@ func genSplit(s, sep string, sepSave, n int) []string { n = Count(s, sep) + 1 } + if n > len(s)+1 { + n = len(s) + 1 + } a := make([]string, n) n-- i := 0 -- cgit v1.3-5-g9baa