Skip to content

ValueError when stringifying large int in AstroidTypeError message #2785

@correctmost

Description

@correctmost

Steps to reproduce

The following code triggers a ValueError in astroid:

a,=7**10000
a.B

This bug was discovered by OSS-Fuzz (an OSS-Fuzz bug report was not filed for it due to infrastructure issues).

Current behavior

Traceback (most recent call last):
  File "pylint/pylint/checkers/utils.py", line 1364, in safe_infer
    value = next(infer_gen)
            ^^^^^^^^^^^^^^^
  File "astroid/astroid/nodes/node_ng.py", line 164, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "astroid/astroid/decorators.py", line 81, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "astroid/astroid/decorators.py", line 44, in wrapped
    for res in _func(node, context, **kwargs):
  File "astroid/astroid/bases.py", line 184, in _infer_stmts
    for inf in stmt.infer(context=context):
  File "astroid/astroid/nodes/node_ng.py", line 164, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "astroid/astroid/decorators.py", line 81, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "astroid/astroid/decorators.py", line 44, in wrapped
    for res in _func(node, context, **kwargs):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/nodes/node_classes.py", line 451, in _infer
    stmts = list(self.assigned_stmts(context=context))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/decorators.py", line 81, in inner
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "astroid/astroid/protocols.py", line 456, in assign_assigned_stmts
    yield from _resolve_assignment_parts(
  File "astroid/astroid/protocols.py", line 497, in _resolve_assignment_parts
    assigned = part.getitem(index_node, context)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/nodes/node_classes.py", line 2136, in getitem
    raise AstroidTypeError(f"{self!r} (value={self.value})")
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit

Expected behavior

No crash

Version

8cb239f

Metadata

Metadata

Assignees

No one assigned

    Labels

    Crash 💥Needs PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions