]> granicus.if.org Git - python/commitdiff
Issue #12687: Fix a possible buffering bug when unpickling text mode (protocol 0...
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 11 Aug 2011 19:04:02 +0000 (21:04 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 11 Aug 2011 19:04:02 +0000 (21:04 +0200)
Lib/test/pickletester.py
Misc/NEWS
Modules/_pickle.c

index a843486a42aba6b6052917b1e3e54ff3420c8c20..e4ab0ddf72f1fabc34a6fdcd32d356d364bb545e 100644 (file)
@@ -1418,6 +1418,19 @@ class AbstractPicklerUnpicklerObjectTests(unittest.TestCase):
     def test_multiple_unpicklings_unseekable(self):
         self._check_multiple_unpicklings(UnseekableIO)
 
+    def test_unpickling_buffering_readline(self):
+        # Issue #12687: the unpickler's buffering logic could fail with
+        # text mode opcodes.
+        data = list(range(10))
+        for proto in protocols:
+            for buf_size in range(1, 11):
+                f = io.BufferedRandom(io.BytesIO(), buffer_size=buf_size)
+                pickler = self.pickler_class(f, protocol=proto)
+                pickler.dump(data)
+                f.seek(0)
+                unpickler = self.unpickler_class(f)
+                self.assertEqual(unpickler.load(), data)
+
 
 if __name__ == "__main__":
     # Print some stuff that can be used to rewrite DATA{0,1,2}
index b8c5877ea58c3e59602bd8c1a47a54a4c8e14aa2..c9a0522cfc7f1655f8210dfd679216636ae4600d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -41,6 +41,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #12687: Fix a possible buffering bug when unpickling text mode
+  (protocol 0, mostly) pickles.
+
 - Issue #10087: Fix the html output format of the calendar module.
 
 - Issue #12540: Prevent zombie IDLE processes on Windows due to changes
index 287f0a3c15affa7eec03db24087406dc0c06b72e..001360b8610931351f2886e5cdf73a56301fb62c 100644 (file)
@@ -1034,9 +1034,8 @@ _Unpickler_Readline(UnpicklerObject *self, char **result)
         num_read = _Unpickler_ReadFromFile(self, READ_WHOLE_LINE);
         if (num_read < 0)
             return -1;
-        *result = self->input_buffer;
         self->next_read_idx = num_read;
-        return num_read;
+        return _Unpickler_CopyLine(self, self->input_buffer, num_read, result);
     }
  
     /* If we get here, we've run off the end of the input string. Return the