Issue #17872: Fix a segfault in marshal.load() when input stream returns

more bytes than requested.
This commit is contained in:
Serhiy Storchaka 2013-07-11 22:20:47 +03:00
parent 244d6252f2
commit 3641a74e1c
3 changed files with 35 additions and 15 deletions

View file

@ -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