Skip to content

compiling an AST with an invalid TypeAlias causes a segmentation fault  #109341

Closed
@15r10nk

Description

@15r10nk

Bug report

Bug description:

The code for the following AST is:

type foo['x'] = Callable

compiling the AST for the given code results in a segmentation fault

from ast import * m = Module( body=[ TypeAlias( name=Subscript( value=Name(id="foo", ctx=Load()), slice=Constant(value="x"), ctx=Store(), ), type_params=[], value=Name(id="Callable", ctx=Load()), ) ], type_ignores=[], ) compile(fix_missing_locations(m), "<file>", "exec")

output (Python 3.12.0rc2+):

fish: Job 1, 'venv3.12/bin/python bug.py' terminated by signal SIGSEGV (Adressbereichsfehler) 

Compiling the code gives the correct syntax error.

compile("type foo['x'] = Callable","<file>","exec")

output (Python 3.12.0rc2+):

Traceback (most recent call last): File "/home/frank/projects/executing/bug.py", line 1, in <module> compile("type foo['x'] = Callable","<file>","exec") File "<file>", line 1 type foo['x'] = Callable ^^^ SyntaxError: invalid syntax 

CPython versions tested on:

3.12

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

Labels

3.12only security fixes3.13bugs and security fixestopic-typingtype-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