]> granicus.if.org Git - python/commitdiff
Merged revisions 74189 via svnmerge from
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 23 Jul 2009 22:31:47 +0000 (22:31 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 23 Jul 2009 22:31:47 +0000 (22:31 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r74189 | amaury.forgeotdarc | 2009-07-23 21:26:02 +0200 (jeu., 23 juil. 2009) | 4 lines

  #6553: crash in cPickle.load(), when given a StringIO with incomplete data.

  Will backport to 2.6, 3.x already fixed a similar issue with issue4298.
........

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

index f7099a1b3009ab3832043d489b913a7b719cbf1a..73ca92696504084f3515b9a2a8ae0334c2a71bd8 100644 (file)
@@ -1,6 +1,7 @@
 import unittest
 import pickle
 import cPickle
+import StringIO
 import pickletools
 import copy_reg
 
@@ -1015,6 +1016,10 @@ class AbstractPickleModuleTests(unittest.TestCase):
         self.module.Pickler(f, -1)
         self.module.Pickler(f, protocol=-1)
 
+    def test_incomplete_input(self):
+        s = StringIO.StringIO("X''.")
+        self.assertRaises(EOFError, self.module.load, s)
+
 class AbstractPersistentPicklerTests(unittest.TestCase):
 
     # This class defines persistent_id() and persistent_load()
index df3c2a53b2d86d90de8faa6e856f3474ddbf2da7..3374e13a988483a389dacc65486a3a89ffc3784e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -273,6 +273,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #6553: Fixed a crash in cPickle.load(), when given a file-like object
+  containing incomplete data.
+
 - Issue #2622: Fixed an ImportError when importing email.messsage from a
   standalone application built with py2exe or py2app.
 
index 1cef5c1f704673370f43057658440da71b6b5e42..8fa4a66c3658baede6a0d11c06c540360a41a229 100644 (file)
@@ -663,6 +663,12 @@ read_other(Unpicklerobject *self, char **s, Py_ssize_t  n)
        self->last_string = str;
 
        if (! (*s = PyString_AsString(str))) return -1;
+
+       if (PyString_GET_SIZE(str) != n) {
+               PyErr_SetNone(PyExc_EOFError);
+               return -1;
+       }
+
        return n;
 }