Skip to content

Parser: error check doesn't propagate errors in NEW_TYPE_COMMENT #145783

@StanFromIreland

Description

@StanFromIreland

Crash report

What happened?

Found by OSS Fuzz in 491369109.

When running the below reproducer with the PyCF_IGNORE_COOKIE and PyCF_TYPE_COMMENTS flags, you get:

>>> a=1 #type: \x80
python: Python/ast.c:1051: _PyAST_Validate: Assertion `!PyErr_Occurred()' failed.
Fatal Python error: Aborted

This occurs because NEW_TYPE_COMMENT() sets p->error_indicator and returns NULL (_PyPegen_new_type_comment() fails on decoding, and returns NULL). However since the field is optional, parsing succeeds. Our current error check does not account for this case.

I will send a patch shortly.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Output from running 'python -VV' on the command line:

No response

Linked PRs

Metadata

Metadata

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-parsertype-crashA hard crash of the interpreter, possibly with a core dump

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions