Skip to content

[P-C2] Parser: infinite loop on unterminated blocks #2

Closed

Description

@godofecht

Description

Many while self.current_token.type != TokenType.RBRACE: loops in src/flow/parser.py (lines ~924, 972, 1004, 1040, 1100, 1370, 1408, 1444) never check for TokenType.EOF.

If the input ends without a closing brace (e.g., truncated file), the parser loops forever because next_token() keeps returning the same EOF token, but the loop condition never becomes true.

def parse_block(self) -> Block:
    self.expect(TokenType.LBRACE)
    statements = []
    while self.current_token.type != TokenType.RBRACE:  # Infinite if EOF
        statements.append(self.parse_statement())
    self.expect(TokenType.RBRACE)

Impact

  • Compiler hangs on malformed input
  • IDE/LSP integration unusable for files being edited (often temporarily malformed)
  • Denial of service if compiler is exposed as a service

Fix

Add and self.current_token.type != TokenType.EOF to all such loop conditions, or use a helper method.

Audit ID: P-C2

Severity: Critical | Category: Compiler - parser.py

Activity

  1. added
    bug
    on Feb 7, 2026
  2. godofecht commented on Feb 9, 2026

    @godofecht
    ContributorAuthor

    Fixed: added EOF guards to all 10 while != RBRACE loops in the parser. The parser now raises SyntaxError('Unterminated ... expected } before end of file') instead of looping forever on truncated input.

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

    bugcompilercritical

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions