Skip to content

go/parser: StructType.End() can overflow the File #48300

Open

Description

@findleyr

As encountered in #48249, StructType.End() can overflow the file (such that File.Offset panics).

This is due to the error recovery here:
https://cs.opensource.google/go/go/+/master:src/go/parser/parser.go;l=675;drc=0406d3a8e5301bd5fd697018e6e8fbb9c75eeb42

Which will set the StructType.Fields.Closing to the end of the file, and then StructType.Fields.End overflows:
https://cs.opensource.google/go/go/+/master:src/go/ast/ast.go;l=252;drc=master

This is a low priority (the logic that gopls was using should have been more robust), but I feel like it should be an invariant of nodes that if Pos() or End() is not token.NoPos, they have a valid offset.

Are there counter-arguments or contradicting precedent?

CC @griesemer @stamblerre

Activity

  1. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Sep 9, 2021
  2. added this to the Backlog milestone on Sep 9, 2021
  3. adonovan commented on Mar 2, 2023

    @adonovan
    Member

    Related: #57490

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.gopls/parsingIssues related to parsing / poor parser recovery.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions