Skip to content

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

@correctmost

Description

@correctmost

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions