From 6e73ff1a31a430b00d9e5aa537dc08cbbe89bd2d Mon Sep 17 00:00:00 2001 From: Alexandre Vassalotti Date: Thu, 5 Dec 2013 19:29:32 -0800 Subject: Issue #19881: Fix bad pickling of large bytes in cpickle. --- Lib/test/pickletester.py | 75 ++++++++++++++++++++++++++++++++++-------------- Misc/NEWS | 4 +++ Modules/_pickle.c | 2 +- 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 1b08dbd..040c26f 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -3,6 +3,7 @@ import io import pickle import pickletools import random +import struct import sys import unittest import weakref @@ -1611,9 +1612,9 @@ class BigmemPickleTests(unittest.TestCase): data = 1 << (8 * size) try: for proto in protocols: + if proto < 2: + continue with self.subTest(proto=proto): - if proto < 2: - continue with self.assertRaises((ValueError, OverflowError)): self.dumps(data, protocol=proto) finally: @@ -1628,13 +1629,17 @@ class BigmemPickleTests(unittest.TestCase): data = b"abcd" * (size // 4) try: for proto in protocols: + if proto < 3: + continue with self.subTest(proto=proto): - if proto < 3: - continue try: pickled = self.dumps(data, protocol=proto) - self.assertTrue(b"abcd" in pickled[:19]) - self.assertTrue(b"abcd" in pickled[-18:]) + header = (pickle.BINBYTES + + struct.pack("proto >= 4) { header[0] = BINBYTES8; _write_size64(header + 1, size); - len = 8; + len = 9; } else { PyErr_SetString(PyExc_OverflowError, -- cgit v0.12