[Python-checkins] bpo-43693: Do not check co_cell2arg if a non-cell offset. (gh-26626)

ericsnowcurrently webhook-mailer at python.org
Wed Jun 9 13:41:04 EDT 2021


https://github.com/python/cpython/commit/e6e34e45222b9c7a63ba92386612acf768082ba0
commit: e6e34e45222b9c7a63ba92386612acf768082ba0
branch: main
author: Eric Snow <ericsnowcurrently at gmail.com>
committer: ericsnowcurrently <ericsnowcurrently at gmail.com>
date: 2021-06-09T11:40:49-06:00
summary:

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

files:
M Objects/frameobject.c

diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index a41d21780fd6e..da56b551b8570 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -981,7 +981,9 @@ PyFrame_FastToLocalsWithError(PyFrameObject *f)
         PyObject *value = fast[i];
         if (f->f_state != FRAME_CLEARED) {
             int cellargoffset = CO_CELL_NOT_AN_ARG;
-            if (co->co_cell2arg != NULL) {
+            if (kind & CO_FAST_CELL && co->co_cell2arg != NULL) {
+                assert(i - co->co_nlocals >= 0);
+                assert(i - co->co_nlocals < co->co_ncellvars);
                 cellargoffset = co->co_cell2arg[i - co->co_nlocals];
             }
             if (kind & CO_FAST_FREE) {
@@ -1093,7 +1095,8 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear)
         PyObject *oldvalue = fast[i];
         int cellargoffset = CO_CELL_NOT_AN_ARG;
         if (kind & CO_FAST_CELL && co->co_cell2arg != NULL) {
-            assert(i >= co->co_nlocals);
+            assert(i - co->co_nlocals >= 0);
+            assert(i - co->co_nlocals < co->co_ncellvars);
             cellargoffset = co->co_cell2arg[i - co->co_nlocals];
         }
         PyObject *cell = NULL;



More information about the Python-checkins mailing list