classification
Title: Passing keyword arguments to types.GenericAlias causes a hard crash
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, kj, miss-islington
Priority: normal Keywords: patch

Created on 2020-12-05 14:31 by kj, last changed 2020-12-06 17:01 by miss-islington. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23656 merged kj, 2020-12-05 14:38
PR 23659 merged miss-islington, 2020-12-05 16:02
PR 23663 merged kj, 2020-12-06 10:57
PR 23666 merged miss-islington, 2020-12-06 16:38
Messages (8)
msg382565 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2020-12-05 14:31
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.
msg382571 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-12-05 16:00
Oh, this looks like I copied the wrong idiom. Good catch!
msg382573 - (view) Author: miss-islington (miss-islington) Date: 2020-12-05 16:02
New changeset 804d6893b801e8f30318afc38c20d4d0e6161db3 by kj in branch 'master':
bpo-42576: Raise TypeError when passing in keyword arguments to GenericAlias (GH-23656)
https://github.com/python/cpython/commit/804d6893b801e8f30318afc38c20d4d0e6161db3
msg382574 - (view) Author: miss-islington (miss-islington) Date: 2020-12-05 16:24
New changeset d5c029b1a9b47737efb8966f804d28b99a2de239 by Miss Islington (bot) in branch '3.9':
bpo-42576: Raise TypeError when passing in keyword arguments to GenericAlias (GH-23656)
https://github.com/python/cpython/commit/d5c029b1a9b47737efb8966f804d28b99a2de239
msg382578 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-12-05 18:18
Thanks for the quick fix!
msg382591 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2020-12-06 10:48
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).
msg382600 - (view) Author: miss-islington (miss-islington) Date: 2020-12-06 16:38
New changeset 6a7fb9d31bce8590e30c44458d1fc1da4539743d by kj in branch 'master':
bpo-42576: Clarify only debug builds are affected in news (GH-23663)
https://github.com/python/cpython/commit/6a7fb9d31bce8590e30c44458d1fc1da4539743d
msg382602 - (view) Author: miss-islington (miss-islington) Date: 2020-12-06 17:01
New changeset 8502d46e3649bedf6b58a30b0a4b6b726e32b84b by Miss Islington (bot) in branch '3.9':
[3.9] bpo-42576: Clarify only debug builds are affected in news (GH-23663) (GH-23666)
https://github.com/python/cpython/commit/8502d46e3649bedf6b58a30b0a4b6b726e32b84b
History
Date User Action Args
2020-12-06 17:01:05miss-islingtonsetmessages: + msg382602
2020-12-06 16:38:31miss-islingtonsetpull_requests: + pull_request22533
2020-12-06 16:38:06miss-islingtonsetmessages: + msg382600
2020-12-06 10:57:13kjsetpull_requests: + pull_request22530
2020-12-06 10:48:56kjsetmessages: + msg382591
2020-12-05 18:18:08gvanrossumsetmessages: + msg382578
2020-12-05 16:28:26kjsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-12-05 16:24:41miss-islingtonsetmessages: + msg382574
2020-12-05 16:02:29miss-islingtonsetpull_requests: + pull_request22526
2020-12-05 16:02:23miss-islingtonsetnosy: + miss-islington
messages: + msg382573
2020-12-05 16:00:51gvanrossumsetmessages: + msg382571
2020-12-05 14:38:42kjsetkeywords: + patch
stage: patch review
pull_requests: + pull_request22524
2020-12-05 14:31:19kjcreate