]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45510: Check both types when specializing subtraction (GH-29995)
authorBrandt Bucher <brandt@python.org>
Thu, 9 Dec 2021 01:17:16 +0000 (17:17 -0800)
committerGitHub <noreply@github.com>
Thu, 9 Dec 2021 01:17:16 +0000 (10:17 +0900)
Python/specialize.c

index cdc535396fa7628bbfa7f7c5bdd0c139342bc374..5121845008100832e83a0e5efdefa184c746975a 100644 (file)
@@ -1490,6 +1490,10 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
             break;
         case NB_SUBTRACT:
         case NB_INPLACE_SUBTRACT:
+            if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) {
+                SPECIALIZATION_FAIL(BINARY_OP, SPEC_FAIL_DIFFERENT_TYPES);
+                goto failure;
+            }
             if (PyLong_CheckExact(lhs)) {
                 *instr = _Py_MAKECODEUNIT(BINARY_OP_SUBTRACT_INT,
                                           _Py_OPARG(*instr));