-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
go/parser: StructType.End() can underflow the File #66683
Comments
Change https://go.dev/cl/576655 mentions this issue: |
Poor parser error recovery may cause Node.End to be zero, or a small positive displacement from zero due to recursive Node.End computation (#66683). This change further refines the bug.Reports for such problems, and additionally repairs the values heuristically to avoid downstream bug.Reports after toGobDiagnostics (#64547). Updates golang/go#66683 Updates golang/go#64547 Change-Id: I7c795622ec6b63574978d2953c82036fcc4425af Reviewed-on: https://go-review.googlesource.com/c/tools/+/576655 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com>
Let's try to fix this for Go 1.23. Adding to the milestone. |
Change https://go.dev/cl/577595 mentions this issue: |
…art/end and refine bug report Poor parser error recovery may cause Node.End to be zero, or a small positive displacement from zero due to recursive Node.End computation (#66683). This change further refines the bug.Reports for such problems, and additionally repairs the values heuristically to avoid downstream bug.Reports after toGobDiagnostics (#64547). Updates golang/go#66683 Updates golang/go#64547 Updates golang/go#66730 Change-Id: I7c795622ec6b63574978d2953c82036fcc4425af Reviewed-on: https://go-review.googlesource.com/c/tools/+/576655 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com> (cherry picked from commit c7b6b8d) Reviewed-on: https://go-review.googlesource.com/c/tools/+/577595 Auto-Submit: Alan Donovan <adonovan@google.com>
@findleyr suggests that a fuzzer connected to an invariant checker would be a good source of regression test cases. |
Shall we expand this issue to introducing and enforcing our stated invariant? |
Perhaps we need an umbrella issue. See also #66790 (comment), which is the beginning of a theory of pos/end in ill-formed trees. |
Change https://go.dev/cl/630675 mentions this issue: |
As we've seen many times, it is currently (unfortunately) possible that go/ast nodes exceed the bounds of the parsed file. Handle this possibility correctly while building the xrefs index. Updates golang/go#66683 Fixes golang/go#70446 Change-Id: If6364876eb7b8ed8ca11a058417aa028d6b55b41 Reviewed-on: https://go-review.googlesource.com/c/tools/+/630675 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Robert Findley <rfindley@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
A struct type with a missing close brace has an StructType.End pos of zero. That means the enclosing nodes such as ReturnStmt may also have a computed End that is zero, or perhaps slightly larger:
I believe this is the root cause of at least some of the many gopls crashes recorded in #64547.
Ultimately this is a problem of parser error recovery. We need to establish the invariants that:
See also:
The text was updated successfully, but these errors were encountered: