From e6f4a3cdf322be2d95e4d8c7fee9dbbdbef733b8 Mon Sep 17 00:00:00 2001 From: Eric Gallager Date: Sun, 22 Sep 2024 03:25:27 -0400 Subject: [PATCH] Fix code scanning alert #23: Incorrect conversion between integer types Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- libgo/go/go/scanner/scanner.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libgo/go/go/scanner/scanner.go b/libgo/go/go/scanner/scanner.go index 23d8db9d1ccdf..5ef60bca85abd 100644 --- a/libgo/go/go/scanner/scanner.go +++ b/libgo/go/go/scanner/scanner.go @@ -16,6 +16,7 @@ import ( "strconv" "unicode" "unicode/utf8" + "math" ) // An ErrorHandler may be provided to Scanner.Init. If a syntax error is @@ -296,8 +297,11 @@ func trailingDigits(text []byte) (int, int, bool) { return 0, 0, false // no ":" } // i >= 0 - n, err := strconv.ParseUint(string(text[i+1:]), 10, 0) - return i + 1, int(n), err == nil + n, err := strconv.ParseUint(string(text[i+1:]), 10, 32) + if err != nil || n > math.MaxInt32 { + return 0, 0, false + } + return i + 1, int(n), true } func (s *Scanner) findLineEnd() bool {