Skip to content

x/tools/gopls: OOB index in stubmethods.fromValueSpec (reported by telemetry) #64545

Closed
@adonovan

Description

@adonovan

This stack 5wndWg was reported by telemetry:

func fromValueSpec(fset *token.FileSet, ti *types.Info, vs *ast.ValueSpec, pos token.Pos) *StubInfo {
	var idx int
	for i, vs := range vs.Values {
		if pos >= vs.Pos() && pos <= vs.End() {
			idx = i
			break
		}
	}

	valueNode := vs.Values[idx] // <-- the crash implies that idx == len(vs.Values) == 0
gopls/bug
golang.org/x/tools/gopls/internal/bug.report:35
golang.org/x/tools/gopls/internal/bug.Errorf:2
golang.org/x/tools/gopls/internal/lsp.(*Server).codeAction.func1.1:2
runtime.gopanic:88
runtime.goPanicIndex:2
golang.org/x/tools/gopls/internal/lsp/analysis/stubmethods.fromValueSpec:9
golang.org/x/tools/gopls/internal/lsp/analysis/stubmethods.GetStubInfo:4
golang.org/x/tools/gopls/internal/lsp/analysis/stubmethods.DiagnosticForError:6
golang.org/x/tools/gopls/internal/lsp.(*Server).codeAction.func1:11
golang.org/x/tools/gopls/internal/lsp.(*Server).codeAction:210
golang.org/x/tools/gopls/internal/lsp.(*Server).CodeAction:1
golang.org/x/tools/gopls/internal/lsp/protocol.serverDispatch:142
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.ServerHandler.func3:5
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.handshaker.func4:52
golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.MustReplyHandler.func1:2
golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.AsyncHandler.func2.2:3
golang.org/x/tools/gopls@v0.14.2 go1.21.2 darwin/arm64 (1)

This OOB index looks very similar (but not the same) as a recent bug in StubMethods: #64087.

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

Dups:

This stack KFS4Ow was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/bug.report:35
golang.org/x/tools/gopls/internal/bug.Errorf:2
golang.org/x/tools/gopls/internal/lsp.(*Server).codeAction.func1.1:2
runtime.gopanic:50
runtime.goPanicIndex:2
golang.org/x/tools/gopls/internal/lsp/analysis/stubmethods.fromValueSpec:9
golang.org/x/tools/gopls/internal/lsp/analysis/stubmethods.GetStubInfo:4
golang.org/x/tools/gopls/internal/lsp/analysis/stubmethods.DiagnosticForError:6
golang.org/x/tools/gopls/internal/lsp.(*Server).codeAction.func1:11
golang.org/x/tools/gopls/internal/lsp.(*Server).codeAction:210
golang.org/x/tools/gopls/internal/lsp.(*Server).CodeAction:1
golang.org/x/tools/gopls/internal/lsp/protocol.serverDispatch:142
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.ServerHandler.func3:5
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.handshaker.func4:52
golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.MustReplyHandler.func1:2
golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.AsyncHandler.func2.2:3
golang.org/x/tools/gopls@v0.14.2 go1.22.0 darwin/arm64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

Activity

added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
goplsIssues related to the Go language server, gopls.
ToolsThis label describes issues relating to any tools in the x/tools repository.
on Dec 4, 2023
added this to the Unreleased milestone on Dec 4, 2023
self-assigned this
on Dec 11, 2023
gopherbot

gopherbot commented on Dec 11, 2023

@gopherbot
Contributor

Change https://go.dev/cl/548737 mentions this issue: gopls/internal/analysis/stubmethods: fix OOB panic in fromValueSpec

added a commit that references this issue on Feb 5, 2024
f40889d
locked and limited conversation to collaborators on Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsInvestigationSomeone 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

      Participants

      @hyangah@adonovan@gopherbot

      Issue actions

        x/tools/gopls: OOB index in stubmethods.fromValueSpec (reported by telemetry) · Issue #64545 · golang/go