Skip to content

ast.parse raises SystemError: <class 'UnicodeDecodeError'> returned a result with an error set #134021

@gabe-sherman

Description

@gabe-sherman

Bug report

Bug description:

The below code triggers the following exception message: SystemError: <class 'UnicodeDecodeError'> returned a result with an error set. On later Python versions(>3.9), this shows up as just a UnicodeDecodeError, so it seems like the issue does not occur in later versions. I tried checking to see if this was known to exist in version 3.9, but didn't see anything, so I am reporting it here. Note that the type_comments argument must be set to True in order for this to occur.

Reproducer

import ast 
d = b'def hello(*onRlionRRasR,#type:RR,rRBRliRRf, o:\n f, o:\n ionRleloionRRasR,#type:RR,rRBRl\x8fRRf, o:\n cRRRlction= la:::::\x1c:\xad\xa2"\n'
parseval1 = ast.parse(d, type_comments = True)

Trace

Traceback (most recent call last):
  File "rep.py", line 5, in <module>
    ast.parse(d, type_comments = True)
  File "/usr/lib/python3.9/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
SystemError: <class 'UnicodeDecodeError'> returned a result with an error set

CPython versions tested on:

3.9

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.9only security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions