diff Python/compile.c @ 45760:16580dc14294

Fix crasher in unpacking assignments with star, where the size constraints weren't checked.
author Thomas Wouters <thomas@python.org>
date Fri, 14 Mar 2008 17:16:59 +0000
parents 2a821e001a2b
children 832c820e9d14
line wrap: on
line diff
--- a/Python/compile.c	Fri Mar 14 13:28:59 2008 +0000
+++ b/Python/compile.c	Fri Mar 14 17:16:59 2008 +0000
@@ -2614,6 +2614,11 @@
 		for (i = 0; i < n; i++) {
 			expr_ty elt = asdl_seq_GET(e->v.List.elts, i);
 			if (elt->kind == Starred_kind && !seen_star) {
+				if ((i >= (1 << 8)) ||
+				    (n-i-1 >= (INT_MAX >> 8)))
+					return compiler_error(c,
+						"too many expressions in "
+						"star-unpacking assignment");
 				ADDOP_I(c, UNPACK_EX, (i + ((n-i-1) << 8)));
 				seen_star = 1;
 				asdl_seq_SET(e->v.List.elts, i, elt->v.Starred.value);
@@ -2642,6 +2647,11 @@
 		for (i = 0; i < n; i++) {
 			expr_ty elt = asdl_seq_GET(e->v.Tuple.elts, i);
 			if (elt->kind == Starred_kind && !seen_star) {
+				if ((i >= (1 << 8)) ||
+				    (n-i-1 >= (INT_MAX >> 8)))
+					return compiler_error(c,
+						"too many expressions in "
+						"star-unpacking assignment");
 				ADDOP_I(c, UNPACK_EX, (i + ((n-i-1) << 8)));
 				seen_star = 1;
 				asdl_seq_SET(e->v.Tuple.elts, i, elt->v.Starred.value);