diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-07-11 19:28:18 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-07-11 19:28:18 (GMT) |
commit | f9e6672ae8044f9dbcbafe98a6b63ab30189770e (patch) | |
tree | 6242914317002844fbb1b7645fa5f458d67e33ad /Lib | |
parent | 4fcf1b2bb74b1e1ea736951b710a6a69cbcd2963 (diff) | |
parent | 3641a74e1c03ce153042d2c21639e5b6b9604f3b (diff) | |
download | cpython-f9e6672ae8044f9dbcbafe98a6b63ab30189770e.zip cpython-f9e6672ae8044f9dbcbafe98a6b63ab30189770e.tar.gz cpython-f9e6672ae8044f9dbcbafe98a6b63ab30189770e.tar.bz2 |
Issue #17872: Fix a segfault in marshal.load() when input stream returns
more bytes than requested.
Diffstat (limited to 'Lib')
-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 292746b..ab06237 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 @@ -259,6 +260,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))) + def _test_eof(self): data = marshal.dumps(("hello", "dolly", None)) for i in range(len(data)): |