Index: Lib/test/pickletester.py =================================================================== --- Lib/test/pickletester.py (revision 73867) +++ Lib/test/pickletester.py (working copy) @@ -1,6 +1,7 @@ import unittest import pickle import cPickle +import StringIO import cStringIO import pickletools import copy_reg @@ -1086,6 +1087,10 @@ self.module.Pickler(f, -1) self.module.Pickler(f, protocol=-1) + def test_bad_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: Modules/cPickle.c =================================================================== --- Modules/cPickle.c (revision 73867) +++ Modules/cPickle.c (working copy) @@ -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; }