Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

MemoryError when parsing deeply nested parentheses #2643

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

MemoryError when parsing deeply nested parentheses #2643

correctmost opened this issue Nov 26, 2024 · 0 comments

Comments

@correctmost
Copy link
Contributor

Steps to reproduce

The following code triggers a MemoryError in astroid:

A=((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((c,j=t

This bug was discovered by OSS-Fuzz:
https://issues.oss-fuzz.com/issues/380930688 (report not public yet)

Current behavior

Traceback (most recent call last):
  File "pylint/pylint/lint/pylinter.py", line 976, in get_ast
    return MANAGER.ast_from_file(filepath, modname, source=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/manager.py", line 167, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/builder.py", line 144, in file_build
    module, builder = self._data_build(data, modname, path)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/builder.py", line 181, in _data_build
    node, parser_module = _parse_string(
                          ^^^^^^^^^^^^^^
  File "astroid/astroid/builder.py", line 476, in _parse_string
    parsed = parser_module.parse(
             ^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/_ast.py", line 29, in parse
    return ast.parse(string, filename=filename, type_comments=type_comments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/ast.py", line 52, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
MemoryError: Parser stack overflowed - Python source too complex to parse

Expected behavior

Python also raises a MemoryError when trying to run the fuzzed A=(((... code, but maybe astroid can handle ast.parse failures more gracefully?

Version

9efc827

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

No branches or pull requests

2 participants