Skip to content

MemoryError when inferring formatted string with large width value #2762

@correctmost

Description

@correctmost

Steps to reproduce

The following code triggers a MemoryError in astroid:

x=f'{0:11111111111}'

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

Current behavior

Traceback (most recent call last):
  File "pylint/pylint/utils/ast_walker.py", line 87, in walk
    callback(astroid)
  File "pylint/pylint/extensions/redefined_variable_type.py", line 100, in visit_assign
    _type = node_type(node.value)
            ^^^^^^^^^^^^^^^^^^^^^
  File "pylint/pylint/checkers/utils.py", line 1501, in node_type
    for var_type in node.infer():
  File "astroid/astroid/nodes/node_ng.py", line 165, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "astroid/astroid/nodes/node_classes.py", line 4785, in _infer
    yield from self._infer_with_values(context)
  File "astroid/astroid/nodes/node_classes.py", line 4793, in _infer_with_values
    for inferred in self._infer_from_values(self.values, context):
  File "astroid/astroid/nodes/node_classes.py", line 4811, in _infer_from_values
    for node in cls._safe_infer_from_node(nodes[0], context, **kwargs):
  File "astroid/astroid/nodes/node_classes.py", line 4832, in _safe_infer_from_node
    yield from node._infer(context, **kwargs)
  File "astroid/astroid/nodes/node_classes.py", line 4702, in _infer
    formatted = format(value_to_format, format_spec.value)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
MemoryError

Expected behavior

No crash

Version

580d17c

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