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

Passing keyword arguments to types.GenericAlias causes a hard crash #86742

Closed
Fidget-Spinner opened this issue Dec 5, 2020 · 8 comments
Closed
Labels
3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@Fidget-Spinner
Copy link
Member

BPO 42576
Nosy @gvanrossum, @miss-islington, @Fidget-Spinner
PRs
  • bpo-42576: Raise TypeError when passing in keyword arguments to GenericAlias #23656
  • [3.9] bpo-42576: Raise TypeError when passing in keyword arguments to GenericAlias (GH-23656) #23659
  • bpo-42576: Clarify only debug builds are affected in news #23663
  • [3.9] bpo-42576: Clarify only debug builds are affected in news (GH-23663) #23666
  • 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-12-05.16:28:26.882>
    created_at = <Date 2020-12-05.14:31:19.254>
    labels = ['interpreter-core', '3.9', '3.10']
    title = 'Passing keyword arguments to types.GenericAlias causes a hard crash'
    updated_at = <Date 2020-12-06.17:01:05.979>
    user = 'https://github.com/Fidget-Spinner'

    bugs.python.org fields:

    activity = <Date 2020-12-06.17:01:05.979>
    actor = 'miss-islington'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-12-05.16:28:26.882>
    closer = 'kj'
    components = ['Interpreter Core']
    creation = <Date 2020-12-05.14:31:19.254>
    creator = 'kj'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42576
    keywords = ['patch']
    message_count = 8.0
    messages = ['382565', '382571', '382573', '382574', '382578', '382591', '382600', '382602']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'miss-islington', 'kj']
    pr_nums = ['23656', '23659', '23663', '23666']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue42576'
    versions = ['Python 3.9', 'Python 3.10']

    @Fidget-Spinner
    Copy link
    Member Author

    I noticed that passing keyword arguments to types.GenericAlias's __new__ causes the interpreter to hard crash and exit due to an assertion failure:

    import types
    types.GenericAlias(bad=float)

    Result:
    Assertion failed: PyTuple_CheckExact(kwnames), file ....\cpython\Python\getargs.c, line 2767

    A simple fix is to just use _PyArg_NoKeywords instead of _PyArg_NoKwnames.

    Looking through the rest of the C code, it seems that apart from GenericAlias, only vectorcalls for various builtins use _PyArg_NoKwnames. However, they don't seem to be affected by the bug.

    @Fidget-Spinner Fidget-Spinner added 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Dec 5, 2020
    @gvanrossum
    Copy link
    Member

    Oh, this looks like I copied the wrong idiom. Good catch!

    @miss-islington
    Copy link
    Contributor

    New changeset 804d689 by kj in branch 'master':
    bpo-42576: Raise TypeError when passing in keyword arguments to GenericAlias (GH-23656)
    804d689

    @miss-islington
    Copy link
    Contributor

    New changeset d5c029b by Miss Islington (bot) in branch '3.9':
    bpo-42576: Raise TypeError when passing in keyword arguments to GenericAlias (GH-23656)
    d5c029b

    @gvanrossum
    Copy link
    Member

    Thanks for the quick fix!

    @Fidget-Spinner
    Copy link
    Member Author

    Thanks for taking the time to review this! I forgot to specify this only affects debug builds in the news entry. I'm opening a PR to edit that because I don't want people to mistake it for an actual interpreter-crashing bug in the release build (that would probably cause some amount of unneeded worry).

    @miss-islington
    Copy link
    Contributor

    New changeset 6a7fb9d by kj in branch 'master':
    bpo-42576: Clarify only debug builds are affected in news (GH-23663)
    6a7fb9d

    @miss-islington
    Copy link
    Contributor

    New changeset 8502d46 by Miss Islington (bot) in branch '3.9':
    [3.9] bpo-42576: Clarify only debug builds are affected in news (GH-23663) (GH-23666)
    8502d46

    @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.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants