summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-06-16 18:29:55 (GMT)
committerGitHub <noreply@github.com>2023-06-16 18:29:55 (GMT)
commit560adb01f97015a6778568e057aa3eeaace3b5f4 (patch)
treee243a5c70012f0f92ea4c6d0992d7391cf2e1ec6 /Python
parent32c0aeb8a796d85720c6046ad855cc1eb65f0c98 (diff)
downloadcpython-560adb01f97015a6778568e057aa3eeaace3b5f4.zip
cpython-560adb01f97015a6778568e057aa3eeaace3b5f4.tar.gz
cpython-560adb01f97015a6778568e057aa3eeaace3b5f4.tar.bz2
[3.12] GH-105840: Fix assertion failures when specializing calls with too many __defaults__ (GH-105863)
GH-105840: Fix assertion failures when specializing calls with too many __defaults__ (GH-105847) (cherry picked from commit 2beab5bdef5fa2a00a59371e6137f769586b7404) Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/specialize.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/Python/specialize.c b/Python/specialize.c
index f168491..63b4446 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1666,9 +1666,9 @@ specialize_py_call(PyFunctionObject *func, _Py_CODEUNIT *instr, int nargs,
}
int argcount = code->co_argcount;
int defcount = func->func_defaults == NULL ? 0 : (int)PyTuple_GET_SIZE(func->func_defaults);
- assert(defcount <= argcount);
int min_args = argcount-defcount;
- if (nargs > argcount || nargs < min_args) {
+ // GH-105840: min_args is negative when somebody sets too many __defaults__!
+ if (min_args < 0 || nargs > argcount || nargs < min_args) {
SPECIALIZATION_FAIL(CALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
return -1;
}