summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_memoryio.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-09-04 04:48:19 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-09-04 04:48:19 (GMT)
commit4e63f7a2b4e3602c420c8ae59a16020b14f8ee13 (patch)
treed9767697d27b578b7bd7cd9cd9e789a541736553 /Lib/test/test_memoryio.py
parentdf6b544ff6f342e8a64056e627867a70413bfdb0 (diff)
downloadcpython-4e63f7a2b4e3602c420c8ae59a16020b14f8ee13.zip
cpython-4e63f7a2b4e3602c420c8ae59a16020b14f8ee13.tar.gz
cpython-4e63f7a2b4e3602c420c8ae59a16020b14f8ee13.tar.bz2
Issue #24989: Fixed buffer overread in BytesIO.readline() if a position is
set beyond size. Based on patch by John Leitch.
Diffstat (limited to 'Lib/test/test_memoryio.py')
-rw-r--r--Lib/test/test_memoryio.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py
index df4ff7a..44d66c3 100644
--- a/Lib/test/test_memoryio.py
+++ b/Lib/test/test_memoryio.py
@@ -166,6 +166,10 @@ class MemoryTestMixin:
memio.seek(0)
self.assertEqual(memio.read(None), buf)
self.assertRaises(TypeError, memio.read, '')
+ memio.seek(len(buf) + 1)
+ self.assertEqual(memio.read(1), self.EOF)
+ memio.seek(len(buf) + 1)
+ self.assertEqual(memio.read(), self.EOF)
memio.close()
self.assertRaises(ValueError, memio.read)
@@ -185,6 +189,9 @@ class MemoryTestMixin:
self.assertEqual(memio.readline(-1), buf)
memio.seek(0)
self.assertEqual(memio.readline(0), self.EOF)
+ # Issue #24989: Buffer overread
+ memio.seek(len(buf) * 2 + 1)
+ self.assertEqual(memio.readline(), self.EOF)
buf = self.buftype("1234567890\n")
memio = self.ioclass((buf * 3)[:-1])
@@ -217,6 +224,9 @@ class MemoryTestMixin:
memio.seek(0)
self.assertEqual(memio.readlines(None), [buf] * 10)
self.assertRaises(TypeError, memio.readlines, '')
+ # Issue #24989: Buffer overread
+ memio.seek(len(buf) * 10 + 1)
+ self.assertEqual(memio.readlines(), [])
memio.close()
self.assertRaises(ValueError, memio.readlines)
@@ -238,6 +248,9 @@ class MemoryTestMixin:
self.assertEqual(line, buf)
i += 1
self.assertEqual(i, 10)
+ # Issue #24989: Buffer overread
+ memio.seek(len(buf) * 10 + 1)
+ self.assertEqual(list(memio), [])
memio = self.ioclass(buf * 2)
memio.close()
self.assertRaises(ValueError, memio.__next__)