Merged revisions 77352-77354 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 7 Jan 2010 18:04:12 +0000 (18:04 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 7 Jan 2010 18:04:12 +0000 (18:04 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77352 | antoine.pitrou | 2010-01-07 18:46:49 +0100 (jeu., 07 janv. 2010) | 5 lines

  Issue #7455: Fix possible crash in cPickle on invalid input.  Patch by
  Florent Xicluna.
........
  r77353 | antoine.pitrou | 2010-01-07 18:49:37 +0100 (jeu., 07 janv. 2010) | 3 lines

  Fix attribution. Florent actually repackaged and reviewed Victor's patch (sorry!).
........
  r77354 | antoine.pitrou | 2010-01-07 18:54:10 +0100 (jeu., 07 janv. 2010) | 3 lines

  Fix reattribution mistake when fixing attribution mistake!
........

Lib/test/pickletester.py
Misc/NEWS
Modules/cPickle.c

index c22085ad5c5cb065333dfc5100a33068dc97cae5..2454af13eddfb2c57c6401cd58bc04ce172e80fd 100644 (file)
@@ -1029,6 +1029,15 @@ class AbstractPickleModuleTests(unittest.TestCase):
         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):
 
index dbdf47a10721cac812e7fd1542362cc7a623eaa8..85faf59415bdd576d4df5e22074c06129d38a6a0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -48,6 +48,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #7455: Fix possible crash in cPickle on invalid input.  Patch by
+  Victor Stinner.
+
 - Issue #6511: ZipFile now raises BadZipfile (instead of an IOError) when
   opening an empty or very small file.
 
index 4e53ae6722714dd075b6ae82d13d660880814e87..331fca2f7c2ceb54f48708c5a03848180a8767f1 100644 (file)
@@ -4033,7 +4033,7 @@ load_pop(Unpicklerobject *self)
        */
        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;