Skip to content

Commit 19e1acb

Browse files
gh-142883: avoid calling stale numeric slot after __index__
1 parent 888d101 commit 19e1acb

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Objects/typeobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9714,13 +9714,19 @@ wrap_indexargfunc(PyObject *self, PyObject *args, void *wrapped)
97149714
ssizeargfunc func = (ssizeargfunc)wrapped;
97159715
PyObject* o;
97169716
Py_ssize_t i;
9717+
PyTypeObject *type_before = Py_TYPE(self);
97179718

97189719
if (!check_num_args(args, 1))
97199720
return NULL;
97209721
o = PyTuple_GET_ITEM(args, 0);
97219722
i = PyNumber_AsSsize_t(o, PyExc_OverflowError);
97229723
if (i == -1 && PyErr_Occurred())
97239724
return NULL;
9725+
if (Py_TYPE(self) != type_before) {
9726+
PyErr_SetString(PyExc_TypeError,
9727+
"object mutated during numeric operation");
9728+
return NULL;
9729+
}
97249730
return (*func)(self, i);
97259731
}
97269732

0 commit comments

Comments
 (0)