From cbdad4fc3cecbdfcee4e9d30df04916a151bfc16 Mon Sep 17 00:00:00 2001 From: Youlin Feng Date: Thu, 4 Sep 2025 09:17:26 +0800 Subject: cmd/go: check pattern for utf8 validity before call regexp.MustCompile Do not panic if the package path or the package version contains invalid UTF-8 characters. Fixes #75251 Change-Id: Ib787e74277cf814253857b911d378ea5e53d8824 Reviewed-on: https://go-review.googlesource.com/c/go/+/700815 Reviewed-by: Michael Matloob LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Alexander Reviewed-by: Michael Matloob --- src/cmd/internal/pkgpattern/pkgpattern.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/cmd/internal') diff --git a/src/cmd/internal/pkgpattern/pkgpattern.go b/src/cmd/internal/pkgpattern/pkgpattern.go index 1496eebb3e..5bbe8a52fb 100644 --- a/src/cmd/internal/pkgpattern/pkgpattern.go +++ b/src/cmd/internal/pkgpattern/pkgpattern.go @@ -7,6 +7,7 @@ package pkgpattern import ( "regexp" "strings" + "unicode/utf8" ) // Note: most of this code was originally part of the cmd/go/internal/search @@ -71,7 +72,7 @@ func matchPatternInternal(pattern string, vendorExclude bool) func(name string) const vendorChar = "\x00" - if vendorExclude && strings.Contains(pattern, vendorChar) { + if vendorExclude && strings.Contains(pattern, vendorChar) || !utf8.ValidString(pattern) { return func(name string) bool { return false } } -- cgit v1.3