diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2009-07-23 19:26:02 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2009-07-23 19:26:02 (GMT) |
commit | 74b301678315068f4e1283fadcc5232cc94426ca (patch) | |
tree | 82d97fa060675f230739859b2f800b47b6afae3a | |
parent | 617a5588d1e5d0ad4cf791646c053064df74aea2 (diff) | |
download | cpython-74b301678315068f4e1283fadcc5232cc94426ca.zip cpython-74b301678315068f4e1283fadcc5232cc94426ca.tar.gz cpython-74b301678315068f4e1283fadcc5232cc94426ca.tar.bz2 |
#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.
-rw-r--r-- | Lib/test/pickletester.py | 5 | ||||
-rw-r--r-- | Misc/NEWS | 7 | ||||
-rw-r--r-- | Modules/cPickle.c | 6 |
3 files changed, 16 insertions, 2 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 7306aa8..8f96d74 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1,6 +1,7 @@ import unittest import pickle import cPickle +import StringIO import cStringIO import pickletools import copy_reg @@ -1086,6 +1087,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() @@ -351,7 +351,10 @@ Core and Builtins Library ------- -- Issue #6545: Removed assert statements in distutils.Extension, so the +- Issue #6553: Fixed a crash in cPickle.load(), when given a file-like object + containing incomplete data. + +- Issue #6545: Removed assert statements in distutils.Extension, so the behavior is similar when used with -O. - unittest has been split up into a package. All old names should still work. @@ -360,7 +363,7 @@ Library know how to handle a comparison without loss of precision. Also add correct handling of infinities and nans for comparisons with float. -- Issue #6415: Fixed warnings.warn sagfault on bad formatted string. +- Issue #6415: Fixed warnings.warn segfault on bad formatted string. - Issue #6466: now distutils.cygwinccompiler and distutils.emxccompiler uses the same refactored function to get gcc/ld/dllwrap versions numbers. diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 486e86f..a849424 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -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; } |