Skip to content

MemoryError in _multiply_seq_by_int when constructing large list #2523

@correctmost

Description

@correctmost

Steps to reproduce

The following code triggers a MemoryError in astroid:

a = [[]] * 825 * 16547118

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

Related fix from the past:

Current behavior

Exception on node <AssignName.a l.1 at 0x73b77c659520> in file 'corpus/a.py'
Traceback (most recent call last):
  File "pylint/pylint/checkers/utils.py", line 1365, in safe_infer
    value = next(infer_gen)
            ^^^^^^^^^^^^^^^
  File "astroid/astroid/nodes/node_ng.py", line 168, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/decorators.py", line 69, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "astroid/astroid/decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/nodes/_base_nodes.py", line 336, in _filter_operation_errors
    for result in infer_callable(context):
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/nodes/node_classes.py", line 1555, in _infer_binop
    yield from self._infer_binary_operation(
  File "astroid/astroid/nodes/_base_nodes.py", line 648, in _infer_binary_operation
    results = list(method())
              ^^^^^^^^^^^^^^
  File "astroid/astroid/decorators.py", line 69, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "astroid/astroid/protocols.py", line 204, in tl_infer_binary_op
    yield _multiply_seq_by_int(self, opnode, other.value, context)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/protocols.py", line 153, in _multiply_seq_by_int
    node.elts = list(filtered_elts) * value
                ~~~~~~~~~~~~~~~~~~~~^~~~~~~
MemoryError

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

Traceback (most recent call last):
  File "pylint/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "pylint/pylint/checkers/base/name_checker/checker.py", line 423, in visit_assignname
    inferred_assign_type = utils.safe_infer(assign_type.value)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pylint/pylint/checkers/utils.py", line 1369, in safe_infer
    raise AstroidError from e
astroid.exceptions.AstroidError

Expected behavior

No crash

Version

d8dbc46

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions