Skip to content

x/tools/gopls: Completion: OOB panic in server.toProtocolCompletionItems #77050

@adonovan

Description

@adonovan
#!stacks
"goPanicSliceB" && "completion.Selection.Suffix" && "toProtocolCompletionItems"

Issue created by stacks.

func (p Selection) PrefixRange() (protocol.Range, error) {
	return p.mapper.PosRange(p.tokFile, p.start, p.cursor)
}

func (p Selection) Prefix() string {
	return p.content[:p.cursor-p.start]
}

func (p Selection) Suffix() string {
	return p.content[p.cursor-p.start:]  // <--- out of bounds panic, after a successful call to PrefixRange 
}

panicSliceB indicates failure of the p.cursor-p.start <= len(p.content) assertion.

This stack BigXFw was reported by telemetry:

golang.org/x/tools/gopls@v0.16.0 go1.23.12 darwin/amd64 gopls.client=vscode (5)

Use this command to reproduce the executable:
(HOME=$(mktemp -d); GOOS=darwin GOARCH=amd64 GOTOOLCHAIN=go1.23.12 go install golang.org/x/tools/gopls@v0.16.0 && find $HOME/go/bin -type f)
To disassemble: go tool objdump exe | less

Metadata

Metadata

Assignees

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/telemetry-wins

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions