Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: slice OOB panic in fixAST on array type #70745

Closed
adonovan opened this issue Dec 9, 2024 · 10 comments
Closed

x/tools/gopls: slice OOB panic in fixAST on array type #70745

adonovan opened this issue Dec 9, 2024 · 10 comments
Assignees
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Dec 9, 2024

#!stacks
"goPanicSliceAcap" && "parsego.fixArrayType:+18"

Issue created by stacks.

Looks like the indices that were sliced were not what was checked with safetoken:

func fixArrayType(bad *ast.BadExpr, parent ast.Node, tok *token.File, src []byte) bool {
...
	// Avoid doing tok.Offset(to) since that panics if badExpr ends at EOF.
	// It also panics if the position is not in the range of the file, and
	// badExprs may not necessarily have good positions, so check first.
	fromOffset, toOffset, err := safetoken.Offsets(tok, from, to-1)
	if err != nil {
		return false
	}
	exprBytes = append(exprBytes, src[fromOffset:toOffset+1]...) // <------ goPanicSliceAcap

This stack N2S9sg was reported by telemetry:

golang.org/x/tools/gopls@v0.16.1 go1.23.0 darwin/arm64 other (1)

Dups: P6TRhg e_PFBQ LmYeow Xc5VZA f1_jlA jAiVQA Y9oucw 7EmzGg

@adonovan adonovan added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. gopls/telemetry-wins labels Dec 9, 2024
@gopherbot gopherbot added this to the Unreleased milestone Dec 9, 2024
@adonovan adonovan modified the milestones: Unreleased, gopls/v0.18.0 Dec 9, 2024
@adonovan adonovan self-assigned this Dec 30, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/639397 mentions this issue: gopls/internal/cache/parsego: fix OOB panic in fixAST

@adonovan
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants