diff --git a/internal/scanner/scanner.go b/internal/scanner/scanner.go index 967c44f10f..b591dffa53 100644 --- a/internal/scanner/scanner.go +++ b/internal/scanner/scanner.go @@ -2056,6 +2056,9 @@ func SkipTriviaEx(text string, pos int, options *SkipTriviaOptions) int { // Keep in sync with couldStartTrivia for { ch, size := utf8.DecodeRuneInString(text[pos:]) + if size == 0 { + return pos + } switch ch { case '\r': if pos+1 < textLen && text[pos+1] == '\n' { @@ -2143,6 +2146,11 @@ func isConflictMarkerTrivia(text string, pos int) bool { panic("pos < 0") } + // Check bounds before accessing text[pos] + if pos >= len(text) { + return false + } + // Conflict markers must be at the start of a line. var prev rune if pos >= 2 {