summaryrefslogtreecommitdiffstats
path: root/Python/specialize.c
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2022-11-10 11:50:34 (GMT)
committerGitHub <noreply@github.com>2022-11-10 11:50:34 (GMT)
commit9d692841691590c25e6cf5b2250a594d3bf54825 (patch)
tree82a0948fc0096f8d2e0b9aaa83a86057212582c8 /Python/specialize.c
parent26726c76494d85c7b565b764c732dd4473458409 (diff)
downloadcpython-9d692841691590c25e6cf5b2250a594d3bf54825.zip
cpython-9d692841691590c25e6cf5b2250a594d3bf54825.tar.gz
cpython-9d692841691590c25e6cf5b2250a594d3bf54825.tar.bz2
GH-99257: Check the owner's type when specializing slots (GH-99258)
Diffstat (limited to 'Python/specialize.c')
-rw-r--r--Python/specialize.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Python/specialize.c b/Python/specialize.c
index 61d7a5d..f845967 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -740,6 +740,10 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name)
PyMemberDescrObject *member = (PyMemberDescrObject *)descr;
struct PyMemberDef *dmem = member->d_member;
Py_ssize_t offset = dmem->offset;
+ if (!PyObject_TypeCheck(owner, member->d_common.d_type)) {
+ SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_EXPECTED_ERROR);
+ goto fail;
+ }
if (dmem->flags & PY_AUDIT_READ) {
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_AUDITED_SLOT);
goto fail;
@@ -849,6 +853,10 @@ _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name)
PyMemberDescrObject *member = (PyMemberDescrObject *)descr;
struct PyMemberDef *dmem = member->d_member;
Py_ssize_t offset = dmem->offset;
+ if (!PyObject_TypeCheck(owner, member->d_common.d_type)) {
+ SPECIALIZATION_FAIL(STORE_ATTR, SPEC_FAIL_EXPECTED_ERROR);
+ goto fail;
+ }
if (dmem->flags & READONLY) {
SPECIALIZATION_FAIL(STORE_ATTR, SPEC_FAIL_ATTR_READ_ONLY);
goto fail;