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

ValueError when stringifying namedtuple exception that contains invalid format string #2519

Open
correctmost opened this issue Aug 26, 2024 · 1 comment

Comments

@correctmost
Copy link
Contributor

Steps to reproduce

The following code triggers a ValueError in astroid:

namedtuple('a','}').format()

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

Current behavior

Exception on node <Module.a l.0 at 0x70283aefedb0> 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 86, 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/node_classes.py", line 1091, in _infer_attribute
    for owner in node.expr.infer(context):
                 ^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/nodes/node_ng.py", line 147, in infer
    for result in self._explicit_inference(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "astroid/astroid/inference_tip.py", line 70, in inner
    raise e from None
  File "astroid/astroid/inference_tip.py", line 66, in inner
    func(node, context, **kwargs)
  File "astroid/astroid/brain/brain_namedtuple_enum.py", line 228, in infer_named_tuple
    raise UseInferenceDefault("ValueError: " + str(exc)) from exc
                                               ^^^^^^^^
  File "astroid/astroid/exceptions.py", line 67, in __str__
    return self.message.format(**vars(self))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Single '}' encountered in format string

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/docstring_checker.py", line 108, in visit_module
    self._check_docstring("module", node)
  File "pylint/pylint/checkers/base/docstring_checker.py", line 187, in _check_docstring
    func = utils.safe_infer(node.body[0].value.func)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pylint/pylint/checkers/utils.py", line 1369, in safe_infer
    raise 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

4 participants
@Pierre-Sassoulas @correctmost and others