summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-13 10:11:03 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-13 10:11:03 (GMT)
commit5a1f152d198722aa4c36e65f952bc92e0f8ac747 (patch)
tree8df88c66b73216070beab0171d37ccfbe98f95f9 /Lib
parentbebd2063e1f3b0d22cdf1d4d6e0b44468132173c (diff)
parent7e0191170e95ffd9c95d840a5631e0f1831998f9 (diff)
downloadcpython-5a1f152d198722aa4c36e65f952bc92e0f8ac747.zip
cpython-5a1f152d198722aa4c36e65f952bc92e0f8ac747.tar.gz
cpython-5a1f152d198722aa4c36e65f952bc92e0f8ac747.tar.bz2
Issue #5308: Raise ValueError when marshalling too large object (a sequence
with size >= 2**31), instead of producing illegal marshal data.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_marshal.py61
1 files changed, 54 insertions, 7 deletions
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index 83c348c..230697e 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -279,16 +279,63 @@ class BugsTestCase(unittest.TestCase):
unicode_string = 'T'
self.assertRaises(TypeError, marshal.loads, unicode_string)
+LARGE_SIZE = 2**31
+character_size = 4 if sys.maxunicode > 0xFFFF else 2
+pointer_size = 8 if sys.maxsize > 0xFFFFFFFF else 4
+
+class NullWriter:
+ def write(self, s):
+ pass
+
+@unittest.skipIf(LARGE_SIZE > sys.maxsize, "test cannot run on 32-bit systems")
+class LargeValuesTestCase(unittest.TestCase):
+ def check_unmarshallable(self, data):
+ self.assertRaises(ValueError, marshal.dump, data, NullWriter())
+
+ @support.bigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False)
+ def test_bytes(self, size):
+ self.check_unmarshallable(b'x' * size)
+
+ @support.bigmemtest(size=LARGE_SIZE, memuse=character_size, dry_run=False)
+ def test_str(self, size):
+ self.check_unmarshallable('x' * size)
+
+ @support.bigmemtest(size=LARGE_SIZE, memuse=pointer_size, dry_run=False)
+ def test_tuple(self, size):
+ self.check_unmarshallable((None,) * size)
+
+ @support.bigmemtest(size=LARGE_SIZE, memuse=pointer_size, dry_run=False)
+ def test_list(self, size):
+ self.check_unmarshallable([None] * size)
+
+ @support.bigmemtest(size=LARGE_SIZE,
+ memuse=pointer_size*12 + sys.getsizeof(LARGE_SIZE-1),
+ dry_run=False)
+ def test_set(self, size):
+ self.check_unmarshallable(set(range(size)))
+
+ @support.bigmemtest(size=LARGE_SIZE,
+ memuse=pointer_size*12 + sys.getsizeof(LARGE_SIZE-1),
+ dry_run=False)
+ def test_frozenset(self, size):
+ self.check_unmarshallable(frozenset(range(size)))
+
+ @support.bigmemtest(size=LARGE_SIZE, memuse=1, dry_run=False)
+ def test_bytearray(self, size):
+ self.check_unmarshallable(bytearray(size))
+
def test_main():
support.run_unittest(IntTestCase,
- FloatTestCase,
- StringTestCase,
- CodeTestCase,
- ContainerTestCase,
- ExceptionTestCase,
- BufferTestCase,
- BugsTestCase)
+ FloatTestCase,
+ StringTestCase,
+ CodeTestCase,
+ ContainerTestCase,
+ ExceptionTestCase,
+ BufferTestCase,
+ BugsTestCase,
+ LargeValuesTestCase,
+ )
if __name__ == "__main__":
test_main()