[Python-checkins] cpython (merge 3.6 -> default): Issue #24098: Fixed possible crash when AST is changed in process of

serhiy.storchaka python-checkins at python.org
Fri Oct 7 14:57:45 EDT 2016


https://hg.python.org/cpython/rev/def217aaad2f
changeset:   104349:def217aaad2f
parent:      104345:8ed6c53c3432
parent:      104348:7528154cadaa
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Fri Oct 07 21:56:24 2016 +0300
summary:
  Issue #24098: Fixed possible crash when AST is changed in process of
compiling it.

files:
  Misc/NEWS           |    3 +
  Parser/asdl_c.py    |    7 +
  Python/Python-ast.c |  220 ++++++++++++++++++++++++++++++++
  3 files changed, 230 insertions(+), 0 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #24098: Fixed possible crash when AST is changed in process of
+  compiling it.
+
 - Issue #28201: Dict reduces possibility of 2nd conflict in hash table when
   hashes have same lower bits.
 
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -526,6 +526,13 @@
             self.emit("res = obj2ast_%s(PyList_GET_ITEM(tmp, i), &value, arena);" %
                       field.type, depth+2, reflow=False)
             self.emit("if (res != 0) goto failed;", depth+2)
+            self.emit("if (len != PyList_GET_SIZE(tmp)) {", depth+2)
+            self.emit("PyErr_SetString(PyExc_RuntimeError, \"%s field \\\"%s\\\" "
+                      "changed size during iteration\");" %
+                      (name, field.name),
+                      depth+3, reflow=False)
+            self.emit("goto failed;", depth+3)
+            self.emit("}", depth+2)
             self.emit("asdl_seq_SET(%s, i, value);" % field.name, depth+2)
             self.emit("}", depth+1)
         else:
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -3997,6 +3997,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -4032,6 +4036,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -4089,6 +4097,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -4192,6 +4204,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -4216,6 +4232,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(decorator_list, i, value);
             }
             Py_CLEAR(tmp);
@@ -4288,6 +4308,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -4312,6 +4336,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(decorator_list, i, value);
             }
             Py_CLEAR(tmp);
@@ -4373,6 +4401,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(bases, i, value);
             }
             Py_CLEAR(tmp);
@@ -4397,6 +4429,10 @@
                 keyword_ty value;
                 res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(keywords, i, value);
             }
             Py_CLEAR(tmp);
@@ -4421,6 +4457,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -4445,6 +4485,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(decorator_list, i, value);
             }
             Py_CLEAR(tmp);
@@ -4502,6 +4546,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(targets, i, value);
             }
             Py_CLEAR(tmp);
@@ -4538,6 +4586,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(targets, i, value);
             }
             Py_CLEAR(tmp);
@@ -4713,6 +4765,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -4737,6 +4793,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(orelse, i, value);
             }
             Py_CLEAR(tmp);
@@ -4797,6 +4857,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -4821,6 +4885,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(orelse, i, value);
             }
             Py_CLEAR(tmp);
@@ -4869,6 +4937,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -4893,6 +4965,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(orelse, i, value);
             }
             Py_CLEAR(tmp);
@@ -4941,6 +5017,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -4965,6 +5045,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(orelse, i, value);
             }
             Py_CLEAR(tmp);
@@ -5001,6 +5085,10 @@
                 withitem_ty value;
                 res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(items, i, value);
             }
             Py_CLEAR(tmp);
@@ -5025,6 +5113,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -5061,6 +5153,10 @@
                 withitem_ty value;
                 res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(items, i, value);
             }
             Py_CLEAR(tmp);
@@ -5085,6 +5181,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -5155,6 +5255,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -5179,6 +5283,10 @@
                 excepthandler_ty value;
                 res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(handlers, i, value);
             }
             Py_CLEAR(tmp);
@@ -5203,6 +5311,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(orelse, i, value);
             }
             Py_CLEAR(tmp);
@@ -5227,6 +5339,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(finalbody, i, value);
             }
             Py_CLEAR(tmp);
@@ -5296,6 +5412,10 @@
                 alias_ty value;
                 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(names, i, value);
             }
             Py_CLEAR(tmp);
@@ -5343,6 +5463,10 @@
                 alias_ty value;
                 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(names, i, value);
             }
             Py_CLEAR(tmp);
@@ -5388,6 +5512,10 @@
                 identifier value;
                 res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(names, i, value);
             }
             Py_CLEAR(tmp);
@@ -5423,6 +5551,10 @@
                 identifier value;
                 res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(names, i, value);
             }
             Py_CLEAR(tmp);
@@ -5564,6 +5696,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(values, i, value);
             }
             Py_CLEAR(tmp);
@@ -5760,6 +5896,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(keys, i, value);
             }
             Py_CLEAR(tmp);
@@ -5784,6 +5924,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(values, i, value);
             }
             Py_CLEAR(tmp);
@@ -5819,6 +5963,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(elts, i, value);
             }
             Py_CLEAR(tmp);
@@ -5866,6 +6014,10 @@
                 comprehension_ty value;
                 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(generators, i, value);
             }
             Py_CLEAR(tmp);
@@ -5913,6 +6065,10 @@
                 comprehension_ty value;
                 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(generators, i, value);
             }
             Py_CLEAR(tmp);
@@ -5972,6 +6128,10 @@
                 comprehension_ty value;
                 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(generators, i, value);
             }
             Py_CLEAR(tmp);
@@ -6019,6 +6179,10 @@
                 comprehension_ty value;
                 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(generators, i, value);
             }
             Py_CLEAR(tmp);
@@ -6132,6 +6296,10 @@
                 cmpop_ty value;
                 res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(ops, i, value);
             }
             Py_CLEAR(tmp);
@@ -6156,6 +6324,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(comparators, i, value);
             }
             Py_CLEAR(tmp);
@@ -6204,6 +6376,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(args, i, value);
             }
             Py_CLEAR(tmp);
@@ -6228,6 +6404,10 @@
                 keyword_ty value;
                 res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(keywords, i, value);
             }
             Py_CLEAR(tmp);
@@ -6352,6 +6532,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(values, i, value);
             }
             Py_CLEAR(tmp);
@@ -6624,6 +6808,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(elts, i, value);
             }
             Py_CLEAR(tmp);
@@ -6671,6 +6859,10 @@
                 expr_ty value;
                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(elts, i, value);
             }
             Py_CLEAR(tmp);
@@ -6836,6 +7028,10 @@
                 slice_ty value;
                 res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(dims, i, value);
             }
             Py_CLEAR(tmp);
@@ -7196,6 +7392,10 @@
             expr_ty value;
             res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
             if (res != 0) goto failed;
+            if (len != PyList_GET_SIZE(tmp)) {
+                PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
+                goto failed;
+            }
             asdl_seq_SET(ifs, i, value);
         }
         Py_CLEAR(tmp);
@@ -7302,6 +7502,10 @@
                 stmt_ty value;
                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
                 if (res != 0) goto failed;
+                if (len != PyList_GET_SIZE(tmp)) {
+                    PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
+                    goto failed;
+                }
                 asdl_seq_SET(body, i, value);
             }
             Py_CLEAR(tmp);
@@ -7348,6 +7552,10 @@
             arg_ty value;
             res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena);
             if (res != 0) goto failed;
+            if (len != PyList_GET_SIZE(tmp)) {
+                PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
+                goto failed;
+            }
             asdl_seq_SET(args, i, value);
         }
         Py_CLEAR(tmp);
@@ -7382,6 +7590,10 @@
             arg_ty value;
             res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena);
             if (res != 0) goto failed;
+            if (len != PyList_GET_SIZE(tmp)) {
+                PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
+                goto failed;
+            }
             asdl_seq_SET(kwonlyargs, i, value);
         }
         Py_CLEAR(tmp);
@@ -7406,6 +7618,10 @@
             expr_ty value;
             res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
             if (res != 0) goto failed;
+            if (len != PyList_GET_SIZE(tmp)) {
+                PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
+                goto failed;
+            }
             asdl_seq_SET(kw_defaults, i, value);
         }
         Py_CLEAR(tmp);
@@ -7440,6 +7656,10 @@
             expr_ty value;
             res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
             if (res != 0) goto failed;
+            if (len != PyList_GET_SIZE(tmp)) {
+                PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
+                goto failed;
+            }
             asdl_seq_SET(defaults, i, value);
         }
         Py_CLEAR(tmp);

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list