[Python-checkins] r77352 - in python/trunk: Lib/test/pickletester.py Misc/NEWS Modules/cPickle.c

antoine.pitrou python-checkins at python.org
Thu Jan 7 18:46:49 CET 2010


Author: antoine.pitrou
Date: Thu Jan  7 18:46:49 2010
New Revision: 77352

Log:
Issue #7455: Fix possible crash in cPickle on invalid input.  Patch by
Florent Xicluna.




Modified:
   python/trunk/Lib/test/pickletester.py
   python/trunk/Misc/NEWS
   python/trunk/Modules/cPickle.c

Modified: python/trunk/Lib/test/pickletester.py
==============================================================================
--- python/trunk/Lib/test/pickletester.py	(original)
+++ python/trunk/Lib/test/pickletester.py	Thu Jan  7 18:46:49 2010
@@ -1100,6 +1100,15 @@
         exec teststr in {'__builtins__': builtins}, d
         d['f']()
 
+    def test_bad_input(self):
+        # Test issue4298
+        s = '\x58\0\0\0\x54'
+        self.assertRaises(EOFError, self.module.loads, s)
+        # Test issue7455
+        s = '0'
+        # XXX Why doesn't pickle raise UnpicklingError?
+        self.assertRaises((IndexError, cPickle.UnpicklingError),
+                          self.module.loads, s)
 
 class AbstractPersistentPicklerTests(unittest.TestCase):
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Thu Jan  7 18:46:49 2010
@@ -65,6 +65,9 @@
 Library
 -------
 
+- Issue #7455: Fix possible crash in cPickle on invalid input.  Patch by
+  Florent Xicluna.
+
 - Issue #7092: Fix the DeprecationWarnings emitted by the standard library
   when using the -3 flag.  Patch by Florent Xicluna.
 

Modified: python/trunk/Modules/cPickle.c
==============================================================================
--- python/trunk/Modules/cPickle.c	(original)
+++ python/trunk/Modules/cPickle.c	Thu Jan  7 18:46:49 2010
@@ -4117,7 +4117,7 @@
 	*/
 	if (self->num_marks > 0 && self->marks[self->num_marks - 1] == len) {
 		self->num_marks--;
-	} else if (len >= 0) {
+	} else if (len > 0) {
 		len--;
 		Py_DECREF(self->stack->data[len]);
 		self->stack->length = len;


More information about the Python-checkins mailing list