x/tools/gopls: "slice bounds out of range" crash in ExtractToNewFile
Opened this issue · 8 comments
#!stacks
"goPanicSliceAcap" &&
("golang.ExtractToNewFile:+72" || "golang.ExtractToNewFile:+98")
Issue created by stacks.
fileStart := pgf.File.FileStart
buf.Write(pgf.Src[start-fileStart : end-fileStart]) // slice bounds out of rangeThis stack fFKP7w was reported by telemetry:
crash/crashruntime.gopanic:+69runtime.goPanicSliceAcap:+2golang.org/x/tools/gopls/internal/golang.ExtractToNewFile:+72golang.org/x/tools/gopls/internal/server.(*commandHandler).ExtractToNewFile.func1:+1golang.org/x/tools/gopls/internal/server.(*commandHandler).run.func2:+3golang.org/x/tools/gopls/internal/server.(*commandHandler).run:+77golang.org/x/tools/gopls/internal/server.(*commandHandler).ExtractToNewFile:+1golang.org/x/tools/gopls/internal/protocol/command.Dispatch:+81golang.org/x/tools/gopls/internal/server.(*server).ResolveCodeAction:+21golang.org/x/tools/gopls/internal/protocol.serverDispatch:+46golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3runtime.goexit:+0
golang.org/x/tools/gopls@v0.17.0-pre.2 go1.23.3 linux/amd64 vscode (3)
Dups: VdbNJw uVeilw
Related Issues
- x/tools/gopls: automated issue report (crash) #40819 (closed)
- x/tools/gopls/internal/lsp/template: panic - slice bounds out of range (crash) #57621 (closed)
- x/tools/gopls: panic during completion in go template (crash) #68416 (closed)
- x/tools/gopls: automated issue report (crash) #48492 (closed)
- x/tools/cmd/gopls: crashes with "slice bounds out of range" #31707 (closed)
- x/tools/gopls: crash in mapPosition computing OutgoingCalls to unsafe.Slice #66923 (closed)
- x/tools/gopls: crash in import organization #40208 (closed)
- x/tools/gopls: panic in semantic tokens #51731 (closed)
- x/tools/gopls: crash in adjustRangeForCommentsAndWhiteSpace #55271 (closed)
- x/tools/gopls: out of bounds panic in template completion #49600 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
I think the root cause here is a bad ast.File.FileStart (#70162), because the logic in gopls looks unimpeachable. I'll add more range-checking assertions to gopls so that we get more specific failure information in future.
Change https://go.dev/cl/631675 mentions this issue: gopls/internal/golang: refine crash golang/go#70553
Change https://go.dev/cl/631676 mentions this issue: all: merge master (68e4702) into gopls-release-branch.0.17
This stack VdbNJw was reported by telemetry:
crash/crashruntime.gopanic:+69runtime.goPanicSliceAcap:+2golang.org/x/tools/gopls/internal/golang.ExtractToNewFile:+98golang.org/x/tools/gopls/internal/server.(*commandHandler).ExtractToNewFile.func1:+1golang.org/x/tools/gopls/internal/server.(*commandHandler).run.func2:+3golang.org/x/tools/gopls/internal/server.(*commandHandler).run:+77golang.org/x/tools/gopls/internal/server.(*commandHandler).ExtractToNewFile:+1golang.org/x/tools/gopls/internal/protocol/command.Dispatch:+81golang.org/x/tools/gopls/internal/server.(*server).ResolveCodeAction:+21golang.org/x/tools/gopls/internal/protocol.serverDispatch:+46golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3runtime.goexit:+0
golang.org/x/tools/gopls@v0.17.1 go1.23.3 linux/amd64 vscode (2)
Change https://go.dev/cl/663955 mentions this issue: gopls/internal/golang: yet more refinement of golang/go#70553
I've refined the assertions for v0.19. Pushing this issue to v0.20.
This stack uVeilw was reported by telemetry:
crash/crashruntime.gopanic:+69runtime.goPanicSliceAcap:+2golang.org/x/tools/gopls/internal/golang.ExtractToNewFile:+98golang.org/x/tools/gopls/internal/server.(*commandHandler).ExtractToNewFile.func1:+1golang.org/x/tools/gopls/internal/server.(*commandHandler).run.func2:+3golang.org/x/tools/gopls/internal/server.(*commandHandler).run:+81golang.org/x/tools/gopls/internal/server.(*commandHandler).ExtractToNewFile:+1golang.org/x/tools/gopls/internal/protocol/command.Dispatch:+81golang.org/x/tools/gopls/internal/server.(*server).ExecuteCommand:+28golang.org/x/tools/gopls/internal/protocol.serverDispatch:+674golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3runtime.goexit:+0
golang.org/x/tools/gopls@v0.18.1 go1.23.6 linux/amd64 vscode (1)