1. Armin Rigo
  2. cpython-withatomic

Commits

Antoine Pitrou  committed 15904d5

Issue #7455: Fix possible crash in cPickle on invalid input. Patch by
Florent Xicluna.

  • Participants
  • Parent commits 6144cd4
  • Branches legacy-trunk

Comments (0)

Files changed (3)

File Lib/test/pickletester.py

View file
  • Ignore whitespace
         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):
 

File Misc/NEWS

View file
  • Ignore whitespace
 Library
 -------
 
+- Issue #7455: Fix possible crash in cPickle on invalid input.  Patch by
+  Florent Xicluna.
+
 - Issue #7092: Fix the DeprecationWarnings emitted by the standard library
   when using the -3 flag.  Patch by Florent Xicluna.
 

File Modules/cPickle.c

View file
  • Ignore whitespace
 	*/
 	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;