Skip to content
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

RecursionError with hundreds of consecutive type comments #2526

Open
correctmost opened this issue Aug 26, 2024 · 0 comments
Open

RecursionError with hundreds of consecutive type comments #2526

correctmost opened this issue Aug 26, 2024 · 0 comments

Comments

@correctmost
Copy link
Contributor

Steps to reproduce

The following code triggers a RecursionError in astroid:

a=1 #type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b#type:a=b

This bug was discovered by OSS-Fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65288 (report not public yet)

Current behavior

Traceback (most recent call last):
  File "pylint/pylint/lint/pylinter.py", line 786, in _lint_file
    check_astroid_module(module)
  File "pylint/pylint/lint/pylinter.py", line 1015, in check_astroid_module
    retval = self._check_astroid_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pylint/pylint/lint/pylinter.py", line 1063, in _check_astroid_module
    raw_checker.process_module(node)
  File "pylint/pylint/checkers/symilar.py", line 841, in process_module
    self.append_stream(self.linter.current_name, stream, node.file_encoding)
  File "pylint/pylint/checkers/symilar.py", line 377, in append_stream
    LineSet(
  File "pylint/pylint/checkers/symilar.py", line 682, in __init__
    self._stripped_lines = stripped_lines(
                           ^^^^^^^^^^^^^^^
  File "pylint/pylint/checkers/symilar.py", line 590, in stripped_lines
    tree = astroid.parse("".join(lines))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/builder.py", line 300, in parse
    return builder.string_build(code, modname=module_name, path=path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/builder.py", line 151, in string_build
    module, builder = self._data_build(data, modname, path)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/builder.py", line 206, in _data_build
    module = builder.visit_module(node, modname, node_file, package)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/rebuilder.py", line 171, in visit_module
    [self.visit(child, newnode) for child in node.body],
     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/rebuilder.py", line 448, in visit
    return visit_method(node, parent)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/rebuilder.py", line 656, in visit_assign
    type_annotation = self.check_type_comment(node, parent=newnode)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[...snip...]

  File "astroid/astroid/rebuilder.py", line 595, in check_type_comment
    type_object = self.visit(type_comment_ast.body[0], parent=parent)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/rebuilder.py", line 448, in visit
    return visit_method(node, parent)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/rebuilder.py", line 658, in visit_assign
    targets=[self.visit(child, newnode) for child in node.targets],
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/rebuilder.py", line 448, in visit
    return visit_method(node, parent)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/rebuilder.py", line 1379, in visit_name
    self._save_assignment(newnode)
  File "astroid/astroid/rebuilder.py", line 457, in _save_assignment
    node.parent.set_local(node.name, node)
  File "astroid/astroid/nodes/node_ng.py", line 483, in set_local
    self.parent.set_local(name, stmt)
  File "astroid/astroid/nodes/node_ng.py", line 483, in set_local
    self.parent.set_local(name, stmt)
  File "astroid/astroid/nodes/node_ng.py", line 483, in set_local
    self.parent.set_local(name, stmt)
  [Previous line repeated 241 more times]
RecursionError: maximum recursion depth exceeded

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "pylint/pylint/lint/pylinter.py", line 750, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "pylint/pylint/lint/pylinter.py", line 788, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Expected behavior

No crash

Version

d8dbc46

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

No branches or pull requests

7 participants
@Pierre-Sassoulas @correctmost and others