Skip to content

Commit e6e34e4

Browse files
bpo-43693: Do not check co_cell2arg if a non-cell offset. (gh-26626)
This is the same fix as for PyFrame_LocalsToFast() in gh-26609, but applied to PyFrame_FastToLocalsWithError(). (It should have been in that PR.) https://bugs.python.org/issue43693
1 parent eea8148 commit e6e34e4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Objects/frameobject.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,9 @@ PyFrame_FastToLocalsWithError(PyFrameObject *f)
981981
PyObject *value = fast[i];
982982
if (f->f_state != FRAME_CLEARED) {
983983
int cellargoffset = CO_CELL_NOT_AN_ARG;
984-
if (co->co_cell2arg != NULL) {
984+
if (kind & CO_FAST_CELL && co->co_cell2arg != NULL) {
985+
assert(i - co->co_nlocals >= 0);
986+
assert(i - co->co_nlocals < co->co_ncellvars);
985987
cellargoffset = co->co_cell2arg[i - co->co_nlocals];
986988
}
987989
if (kind & CO_FAST_FREE) {
@@ -1093,7 +1095,8 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear)
10931095
PyObject *oldvalue = fast[i];
10941096
int cellargoffset = CO_CELL_NOT_AN_ARG;
10951097
if (kind & CO_FAST_CELL && co->co_cell2arg != NULL) {
1096-
assert(i >= co->co_nlocals);
1098+
assert(i - co->co_nlocals >= 0);
1099+
assert(i - co->co_nlocals < co->co_ncellvars);
10971100
cellargoffset = co->co_cell2arg[i - co->co_nlocals];
10981101
}
10991102
PyObject *cell = NULL;

0 commit comments

Comments
 (0)