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: crash during internal/imports.scanDirForPackage (crash) #67156

Open
Sangwaniya opened this issue May 3, 2024 · 2 comments
Open
Assignees
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@Sangwaniya
Copy link

gopls version: v0.15.3/go1.21.6
gopls flags:
update flags: proxy
extension version: 0.41.4
environment: Visual Studio Code win32
initialization error: undefined
issue timestamp: Thu, 02 May 2024 17:33:19 GMT
restart history:
Thu, 02 May 2024 17:30:10 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: runtime error: slice bounds out of range [45:44]

goroutine 7611 [running]:
golang.org/x/tools/internal/imports.(*ModuleResolver).scanDirForPackage(0xc001898420, {{0xc004182665%3F, 0x81c8a92bb60e9ba5%3F}, 0x8%3F}, {0xc008108db0, 0x2c})
	  mod.go:727  0x705
golang.org/x/tools/internal/imports.(*ModuleResolver).scan.func3({{0xc004182665%3F, 0xdc5e20%3F}, 0xc0067f8f90%3F}, {0xc008108db0%3F, 0x17d12a8%3F})
	  mod.go:601  0x50
golang.org/x/tools/internal/gopathwalk.(*walker).walk(0xc0067b7830, {0xc0071f8100, 0x37}, 0x0, {0x1200af8, 0xc0071f0380})
	  walk.go:268  0x3d7
golang.org/x/tools/internal/gopathwalk.(*walker).walk(0xc0067b7830, {0xc004182665, 0x2c}, 0x0, {0x1200b30, 0xc0067f8f70})
	  walk.go:334  0x87b
golang.org/x/tools/internal/gopathwalk.walkDir({{0xc004182665%3F, 0xc0045a5f18%3F}, 0xc0045a5f18%3F}, 0xc0067f8f40, 0xc0067f8f30, {0x0%3F, 0x40%3F, 0x4%3F})
	  walk.go:120  0x366
golang.org/x/tools/internal/gopathwalk.WalkSkip(...)
	  walk.go:77
golang.org/x/tools/internal/imports.(*ModuleResolver).scan.func4()
	  mod.go:626  0x2db
created by golang.org/x/tools/internal/imports.(*ModuleResolver).scan in goroutine 4670
	  mod.go:610  0x465
gopls stats -anon { "DirStats": { "Files": 2035, "TestdataFiles": 0, "GoFiles": 1626, "ModFiles": 2, "Dirs": 528 }, "GOARCH": "amd64", "GOOS": "windows", "GOPACKAGESDRIVER": "", "GOPLSCACHE": "", "GoVersion": "go1.21.6", "GoplsVersion": "v0.15.3", "InitialWorkspaceLoadDuration": "7.6558984s", "MemStats": { "HeapAlloc": 31132976, "HeapInUse": 41328640, "TotalAlloc": 79278536 }, "WorkspaceStats": { "Files": { "Total": 2207, "Largest": 1654271, "Errs": 0 }, "Views": [ { "GoCommandVersion": "go1.21.6", "AllPackages": { "Packages": 417, "LargestPackage": 134, "CompiledGoFiles": 2217, "Modules": 49 }, "WorkspacePackages": { "Packages": 0, "LargestPackage": 0, "CompiledGoFiles": 0, "Modules": 0 }, "Diagnostics": 0 } ] } }

OPTIONAL: If you would like to share more information, you can attach your complete gopls logs.

NOTE: THESE MAY CONTAIN SENSITIVE INFORMATION ABOUT YOUR CODEBASE.
DO NOT SHARE LOGS IF YOU ARE WORKING IN A PRIVATE REPOSITORY.

<OPTIONAL: ATTACH LOGS HERE>

@Sangwaniya Sangwaniya changed the title gopls: automated issue report (crash) gopls: issue report (crash) May 3, 2024
@hyangah hyangah changed the title gopls: issue report (crash) gopls: crash during internal/imports.scanDirForPackage (crash) May 3, 2024
@hyangah hyangah changed the title gopls: crash during internal/imports.scanDirForPackage (crash) x/tools/gopls: crash during internal/imports.scanDirForPackage (crash) May 3, 2024
@hyangah hyangah transferred this issue from golang/vscode-go May 3, 2024
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels May 3, 2024
@gopherbot gopherbot added this to the Unreleased milestone May 3, 2024
@hyangah
Copy link
Contributor

hyangah commented May 3, 2024

Thanks for the report @Sangwaniya
Transferring to the gopls issue tracker.

@hyangah hyangah modified the milestones: Unreleased, gopls/v0.15.4 May 3, 2024
@adonovan
Copy link
Member

adonovan commented May 3, 2024

Looks like root.Path has the same length as dir, but is not a prefix of it.

func (r *ModuleResolver) scanDirForPackage(root gopathwalk.Root, dir string) directoryPackageInfo {
	subdir := ""
	if dir != root.Path {
		subdir = dir[len(root.Path)+len("/"):] // slice bounds out of range [45:44]
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants