]> granicus.if.org Git - python/commitdiff
bpo-37502: handle default parameter for buffers argument of pickle.loads correctly...
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>
Thu, 25 Jul 2019 16:00:34 +0000 (00:00 +0800)
committerAntoine Pitrou <antoine@python.org>
Thu, 25 Jul 2019 16:00:34 +0000 (18:00 +0200)
Lib/test/pickletester.py
Misc/NEWS.d/next/Library/2019-07-08-03-15-04.bpo-37502.qZGC4g.rst [new file with mode: 0644]
Modules/_pickle.c

index f8f3bc92e7fe6b632b505c3ef6e0de6505c8207b..2bc99e6becfd0d7ac93506d814eeb0c670cfa8ec 100644 (file)
@@ -2765,6 +2765,11 @@ class AbstractPickleTests(unittest.TestCase):
             with self.assertRaises(pickle.UnpicklingError):
                 self.loads(data, buffers=[])
 
+    def test_inband_accept_default_buffers_argument(self):
+        for proto in range(5, pickle.HIGHEST_PROTOCOL + 1):
+            data_pickled = self.dumps(1, proto, buffer_callback=None)
+            data = self.loads(data_pickled, buffers=None)
+
     @unittest.skipIf(np is None, "Test needs Numpy")
     def test_buffers_numpy(self):
         def check_no_copy(x, y):
diff --git a/Misc/NEWS.d/next/Library/2019-07-08-03-15-04.bpo-37502.qZGC4g.rst b/Misc/NEWS.d/next/Library/2019-07-08-03-15-04.bpo-37502.qZGC4g.rst
new file mode 100644 (file)
index 0000000..4eb6d09
--- /dev/null
@@ -0,0 +1 @@
+pickle.loads() no longer raises TypeError when the buffers argument is set to None
index 054276d85adfe025971549c262665edb13169030..0c53f2e18685af271ed8a7fe40e3628c74289612 100644 (file)
@@ -1653,7 +1653,7 @@ _Unpickler_SetInputEncoding(UnpicklerObject *self,
 static int
 _Unpickler_SetBuffers(UnpicklerObject *self, PyObject *buffers)
 {
-    if (buffers == NULL) {
+    if (buffers == NULL || buffers == Py_None) {
         self->buffers = NULL;
     }
     else {