[Python-checkins] r74190 - in python/branches/release26-maint: Lib/test/pickletester.py Misc/NEWS Modules/cPickle.c

amaury.forgeotdarc python-checkins at python.org
Fri Jul 24 00:31:48 CEST 2009


Author: amaury.forgeotdarc
Date: Fri Jul 24 00:31:47 2009
New Revision: 74190

Log:
Merged revisions 74189 via svnmerge from 
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.
........


Modified:
   python/branches/release26-maint/   (props changed)
   python/branches/release26-maint/Lib/test/pickletester.py
   python/branches/release26-maint/Misc/NEWS
   python/branches/release26-maint/Modules/cPickle.c

Modified: python/branches/release26-maint/Lib/test/pickletester.py
==============================================================================
--- python/branches/release26-maint/Lib/test/pickletester.py	(original)
+++ python/branches/release26-maint/Lib/test/pickletester.py	Fri Jul 24 00:31:47 2009
@@ -1,6 +1,7 @@
 import unittest
 import pickle
 import cPickle
+import StringIO
 import pickletools
 import copy_reg
 
@@ -1015,6 +1016,10 @@
         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()

Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Fri Jul 24 00:31:47 2009
@@ -273,6 +273,9 @@
 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.
 

Modified: python/branches/release26-maint/Modules/cPickle.c
==============================================================================
--- python/branches/release26-maint/Modules/cPickle.c	(original)
+++ python/branches/release26-maint/Modules/cPickle.c	Fri Jul 24 00:31:47 2009
@@ -663,6 +663,12 @@
 	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;
 }
 


More information about the Python-checkins mailing list