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: OOB index panic after parsing go list error from file with //line directives #67360

Closed
thanm opened this issue May 14, 2024 · 8 comments
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

@thanm
Copy link
Contributor

thanm commented May 14, 2024

Working with x/tools at commit 487737a1960720c6595131017ff98eef1586fa04, when I build gopls and use it in an emacs session on this file https://go.dev/play/p/_EKzBXvi29C , I get a crash . Full log attached as text file, but the interesting portion of the trace is here:

[stderr]  panic: runtime error: slice bounds out of range [238:237]
[stderr]  
[stderr]  goroutine 704 gp=0xc0015e6000 m=19 mp=0xc000581c08 [running]:
[stderr]  panic({0xfb57a0?, 0xc0025840d8?})
[stderr]  panic({0xfb57a0?, 0xc0025840d8?})
[jsonrpc] e[13:33:21.074]   <-- client/registerCapability[3] {"jsonrpc":"2.0","method":"client/registerCapability","params":{"registrations":[{"id":"workspace/didChangeWatchedFiles-0","method":"workspace/didChangeWatchedFiles","registerOptions":{"watchers":[{"globPattern":"**/*.{mod,work}","kind":7},{"globPattern":"**/*.{go,mod,sum,work}","kind":7}]}}]},"id":3}
[stderr]  	/w/go.master/src/runtime/panic.go:778 +0x168 fp=0xc00078b8f8 sp=0xc00078b848 pc=0x43e788
[stderr]  runtime.goPanicSliceB(0xee, 0xed)
[stderr]  	/w/go.master/src/runtime/panic.go:154 +0x74 fp=0xc00078b938 sp=0xc00078b8f8 pc=0x43d674
[stderr]  golang.org/x/tools/gopls/internal/protocol.(*Mapper).LineCol8Position(0xc000bd63c0, 0xa, 0x0)
[stderr]  	/w/go1/src/golang.org/x/tools/gopls/internal/protocol/mapper.go:151 +0x1a5 fp=0xc00078b9a0 sp=0xc00078b938 pc=0x7c4b05
[stderr]  golang.org/x/tools/gopls/internal/cache.goPackagesErrorDiagnostics.func1({{0xc0006c87a0, 0xa}, {0xc00013c0c0, 0x38}, 0x1}, 0x38?, {0x1300b00, 0xc000563320}, {0x13099c8, 0xc001f99c20})
[stderr]  	/w/go1/src/golang.org/x/tools/gopls/internal/cache/errors.go:59 +0x145 fp=0xc00078ba20 sp=0xc00078b9a0 pc=0xc6eb65
[stderr]  golang.org/x/tools/gopls/internal/cache.goPackagesErrorDiagnostics({0x13099c8, 0xc001f99c20}, {{0xc0006c87a0, 0xa}, {0xc00013c0c0, 0x38}, 0x1}, 0xc000774300, {0x1300b00, 0xc000563320})
[stderr]  	/w/go1/src/golang.org/x/tools/gopls/internal/cache/errors.go:70 +0xf5 fp=0xc00078bae8 sp=0xc00078ba20 pc=0xc6e6d5
[stderr]  golang.org/x/tools/gopls/internal/cache.computeLoadDiagnostics({0x13099c8, 0xc001f99c20}, 0xc000563320, 0xc000774300)
[stderr]  	/w/go1/src/golang.org/x/tools/gopls/internal/cache/load.go:561 +0x185 fp=0xc00078bc28 sp=0xc00078bae8 pc=0xc797e5
[stderr]  golang.org/x/tools/gopls/internal/cache.(*packageHandleBuilder).buildPackageHandle(0xc0000ee660, {0x13099c8, 0xc001f99c20}, 0xc001f98000)

I am guessing that what's at issue here is the tool-generated counter increments.

Thanks.

log.txt

@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 14, 2024
@gopherbot gopherbot added this to the Unreleased milestone May 14, 2024
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.16.0 May 14, 2024
@adonovan adonovan self-assigned this May 14, 2024
@adonovan
Copy link
Member

Thanks for the bug report. I think the problem is that gopls is parsing an error from go list that doesn't have a line or column, which causes it to use zero for both fields, when the correct value is one. Fix pending.

Which package was this file part of? The error message that triggered the fault is a property of the complete package, not just this file.

@adonovan
Copy link
Member

Which package was this file part of?

Answer: cmd/cover. Never mind.

@thanm
Copy link
Contributor Author

thanm commented May 14, 2024

Thanks for looking into the problem. Admittedly editing the output of cmd/cover is a weird thing to do, but maybe someone else out there might also run into it.

@adonovan
Copy link
Member

adonovan commented May 14, 2024

Can you tell me what exact sequence of steps you used to get the crash? It would be nice to add a test to my CL, but the file by itself doesn't cause a problem, nor do various cmd/cover workflows I've tried. I suspect it's something to do with the file in relation to the other files in your particular workflow, since that's what would cause 'go list' to report an error.

@thanm
Copy link
Contributor Author

thanm commented May 14, 2024

I can see the problem when I copy the file into its own dir and run emacs on it, e.g.

$ mkdir /tmp/xxx
$ cp html.go /tmp/xxx
$ cd /tmp/xxx
$ emacs html.go

Does this work for you?

@adonovan
Copy link
Member

Does this work for you?

Yep! Thanks. (I swear I already tried that, but I think I must have disabled "auto manage" mode in eglot earlier in the day while debugging a different problem and forgotten to reenable it.)

@adonovan
Copy link
Member

adonovan commented May 14, 2024

Minimal repro:

//line html.go:1
package main
import _ "cmd/internal/browser"

causes go list error:

xxx$ gopls check ./html.go 
Log: Loading packages...
Info: Finished loading packages.
Log: Running...
2024/05/14 15:34:16 html.go:2: use of internal package cmd/internal/browser not allowed
panic: runtime error: slice bounds out of range [17:16]
...

Seems like the //line directive is confusing the bounds check.

@adonovan adonovan changed the title x/tools/gopls: crash processing Go file generated by cover tool x/tools/gopls: OOB index panic after parsing go list error from file with //line directives May 14, 2024
@gopherbot
Copy link

Change https://go.dev/cl/585555 mentions this issue: gopls/internal/cache: use 1 not 0 for missing line/col info

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

4 participants