[Python-checkins] python/dist/src/Modules cPickle.c,2.92,2.93

loewis@users.sourceforge.net loewis@users.sourceforge.net
2002年8月04日 01:20:26 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv21958
Modified Files:
	cPickle.c 
Log Message:
Add recursion counter for pickling. Fixes #576084.
2.2 bugfix candidate (may cause RuntimeError for applications that
currently work fine).
Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.92
retrieving revision 2.93
diff -C2 -d -r2.92 -r2.93
*** cPickle.c	2 Aug 2002 02:27:13 -0000	2.92
--- cPickle.c	4 Aug 2002 08:20:23 -0000	2.93
***************
*** 277,280 ****
--- 277,281 ----
 	int bin;
 	int fast; /* Fast mode doesn't save in memo, don't use if circ ref */
+ int nesting;
 	int (*write_func)(struct Picklerobject *, char *, int);
 	char *write_buf;
***************
*** 1868,1871 ****
--- 1869,1878 ----
 	int res = -1, tmp, size;
 
+ if (self->nesting++ > Py_GetRecursionLimit()){
+ 		PyErr_SetString(PyExc_RuntimeError,
+ 				"maximum recursion depth exceeded");
+ 		goto finally;
+ 	}
+ 
 	if (!pers_save && self->pers_func) {
 		if ((tmp = save_pers(self, args, self->pers_func)) != 0) {
***************
*** 2093,2096 ****
--- 2100,2104 ----
 
 finally:
+ 	self->nesting--;
 	Py_XDECREF(py_ob_id);
 	Py_XDECREF(__reduce__);
***************
*** 2315,2318 ****
--- 2323,2327 ----
 	self->bin = bin;
 	self->fast = 0;
+ self->nesting = 0;
 	self->fast_container = 0;
 	self->fast_memo = NULL;

AltStyle によって変換されたページ (->オリジナル) /