diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-07-11 19:20:47 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-07-11 19:20:47 (GMT) |
commit | 3641a74e1c03ce153042d2c21639e5b6b9604f3b (patch) | |
tree | 2548c42f980acdb590551e8f6209322c34f07572 /Lib/test/test_marshal.py | |
parent | 244d6252f2ed17b61c476926faf5c15ba5328ff0 (diff) | |
download | cpython-3641a74e1c03ce153042d2c21639e5b6b9604f3b.zip cpython-3641a74e1c03ce153042d2c21639e5b6b9604f3b.tar.gz cpython-3641a74e1c03ce153042d2c21639e5b6b9604f3b.tar.bz2 |
Issue #17872: Fix a segfault in marshal.load() when input stream returns
more bytes than requested.
Diffstat (limited to 'Lib/test/test_marshal.py')
-rw-r--r-- | Lib/test/test_marshal.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py index 025b53c..7e37f39 100644 --- a/Lib/test/test_marshal.py +++ b/Lib/test/test_marshal.py @@ -2,6 +2,7 @@ from test import support import array +import io import marshal import sys import unittest @@ -279,6 +280,17 @@ class BugsTestCase(unittest.TestCase): unicode_string = 'T' self.assertRaises(TypeError, marshal.loads, unicode_string) + def test_bad_reader(self): + class BadReader(io.BytesIO): + def read(self, n=-1): + b = super().read(n) + if n is not None and n > 4: + b += b' ' * 10**6 + return b + for value in (1.0, 1j, b'0123456789', '0123456789'): + self.assertRaises(ValueError, marshal.load, + BadReader(marshal.dumps(value))) + LARGE_SIZE = 2**31 pointer_size = 8 if sys.maxsize > 0xFFFFFFFF else 4 |