Skip to content

RecursionError on parsing config with many comments #281

@lubomir

Description

@lubomir

kobo.conf.PyConfigParser._get_token skips COMMENT, NL, NEWLINE, INDENT, and DEDENT tokens via recursive self-calls rather than a loop. Each skipped token consumes one Python stack frame, so a config file with many consecutive comment or blank lines will recurse proportionally deep, eventually exhausting the default recursion limit.

Steps to reproduce:

import tempfile
from kobo.conf import PyConfigParser
with tempfile.NamedTemporaryFile(mode="w", suffix=".conf", delete=False) as f:
    for i in range(1000):
        f.write(f"# comment {i}\n")
    f.write("x = 1\n")
    path = f.name
c = PyConfigParser()
c.load_from_file(path)
print("ok:", c["x"])

Expected behavior: Parses successfully.
Actual behavior: RecursionError: maximum recursion depth exceeded

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions