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

Custom AST can crash Python (debug build) #85047

Closed
isidentical opened this issue Jun 5, 2020 · 5 comments
Closed

Custom AST can crash Python (debug build) #85047

isidentical opened this issue Jun 5, 2020 · 5 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@isidentical
Copy link
Sponsor Member

BPO 40870
Nosy @serhiy-storchaka, @pablogsal, @miss-islington, @isidentical
PRs
  • bpo-40870: Invalidate usage of some constants with ast.Name #20649
  • [3.9] bpo-40870: Invalidate usage of some constants with ast.Name (GH-20649) #20675
  • [3.8] bpo-40870: Invalidate usage of some constants with ast.Name (GH-20649) #20676
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-06-06.17:26:34.964>
    created_at = <Date 2020-06-05.09:46:27.807>
    labels = ['interpreter-core', 'type-bug', '3.8', '3.9', '3.10']
    title = 'Custom AST can crash Python (debug build)'
    updated_at = <Date 2020-06-06.17:26:34.963>
    user = 'https://github.com/isidentical'

    bugs.python.org fields:

    activity = <Date 2020-06-06.17:26:34.963>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-06-06.17:26:34.964>
    closer = 'pablogsal'
    components = ['Interpreter Core']
    creation = <Date 2020-06-05.09:46:27.807>
    creator = 'BTaskaya'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40870
    keywords = ['patch']
    message_count = 5.0
    messages = ['370753', '370759', '370819', '370835', '370836']
    nosy_count = 4.0
    nosy_names = ['serhiy.storchaka', 'pablogsal', 'miss-islington', 'BTaskaya']
    pr_nums = ['20649', '20675', '20676']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue40870'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @isidentical
    Copy link
    Sponsor Member Author

    import ast
    t = ast.fix_missing_locations(ast.Expression(ast.Name("True", ast.Load())))
    compile(t, "<t>", "eval")

    compilation of this AST can crash the interpreter for 3.8+

    test_constant_as_name (test.test_ast.AST_Tests) ... python: Python/compile.c:3559: compiler_nameop: Assertion `!_PyUnicode_EqualToASCIIString(name, "None") && !_PyUnicode_EqualToASCIIString(name, "True") && !_PyUnicode_EqualToASCIIString(name, "False")' failed.
    Fatal Python error: Aborted

    I've encountered this while running test suite of 'pytest' with the current master, so I guess there are some usages related this out there. IMHO we should validate this on the PyAST_Validate step to prevent this kind of crashes.

    @isidentical isidentical added interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes type-bug An unexpected behavior, bug, or error labels Jun 5, 2020
    @isidentical
    Copy link
    Sponsor Member Author

    cross-linking pytest issue: pytest-dev/pytest#7322

    @miss-islington
    Copy link
    Contributor

    New changeset 68874a8 by Batuhan Taskaya in branch 'master':
    bpo-40870: Invalidate usage of some constants with ast.Name (GH-20649)
    68874a8

    @miss-islington
    Copy link
    Contributor

    New changeset 90ee51f by Miss Islington (bot) in branch '3.9':
    bpo-40870: Invalidate usage of some constants with ast.Name (GH-20649)
    90ee51f

    @miss-islington
    Copy link
    Contributor

    New changeset 83a9ba4 by Miss Islington (bot) in branch '3.8':
    bpo-40870: Invalidate usage of some constants with ast.Name (GH-20649)
    83a9ba4

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants