Skip to content

x/tools/gopls: impossible SEGV in regexp/syntax.MatchRunePos #73090

Open
@adonovan

Description

@adonovan
#!stacks
"sigpanic" && "MatchRunePos:+9"

Issue created by stacks.

Yet more corruption: either Inst.Rune is a corrupt slice (len + data are inconsistent), or SP is invalid, as there are only two instructions that can fail at this line:

func (i *Inst) MatchRunePos(r rune) int {
	rune := i.Rune

	switch len(rune) {
	case 0:
		return noMatch

	case 1:
		// Special case: single-rune slice is from literal string, not char class.
		r0 := rune[0] <--------- panic here
		if r == r0 {
			return 0
		}
		if Flags(i.Arg)&FoldCase != 0 {
                         --- possible panic while spilling r0 here ---
			for r1 := unicode.SimpleFold(r0); r1 != r0; r1 = unicode.SimpleFold(r1) {
				if r == r1 {
					return 0
				}
			}
		}
TEXT regexp/syntax.(*Inst).MatchRunePos(SB) /Users/adonovan/w/goroot/src/regexp/syntax/prog.go
  prog.go:204           0x10030ef70             f9400b90                MOVD 16(R28), R16                               
  prog.go:204           0x10030ef74             eb3063ff                CMP R16, RSP                                    
  prog.go:204           0x10030ef78             54001109                BLS 136(PC)                                     
  prog.go:204           0x10030ef7c             f81d0ffe                MOVD.W R30, -48(RSP)                            
  prog.go:204           0x10030ef80             f81f83fd                MOVD R29, -8(RSP)                               
  prog.go:204           0x10030ef84             d10023fd                SUB $8, RSP, R29                                
  prog.go:205           0x10030ef88             a9410c02                LDP 16(R0), (R2, R3)             load Inst.Rune data and len
  prog.go:207           0x10030ef8c             f100087f                CMP $2, R3                       switch len               
  prog.go:226           0x10030ef90             5400018d                BLE 12(PC)                       B case01
  ...
case1:  
  prog.go:213           0x10030efcc             b9800042                MOVW (R2), R2             here??     load rune[0] after len check
  prog.go:214           0x10030efd0             6b02003f                CMPW R2, R1                                     
  prog.go:214           0x10030efd4             54000140                BEQ 10(PC)                                      
  prog.go:217           0x10030efd8             b9400803                MOVWU 8(R0), R3                                 
  prog.go:217           0x10030efdc             360003c3                TBZ $0, R3, 30(PC)                              
  prog.go:226           0x10030efe0             b90043e1                MOVW R1, 64(RSP)                                
  prog.go:213           0x10030efe4             b90027e2                MOVW R2, 36(RSP)          here??     spill r0

(The above is arm64 code but the corresponding amd64 instructions are essentially identical.)

This stack CX-PMg was reported by telemetry:

golang.org/x/tools/[email protected] go1.24.1 darwin/amd64 other (1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/memory-corruption"can't happen" gopls crashes (races, unsafe, miscompile, runtime bugs, faulty HW)gopls/telemetry-wins

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions