summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-03 15:07:32 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-03 15:07:32 (GMT)
commitd03ce4ae3d71ba84e1e30cf0cf221ec89ad5aa67 (patch)
tree8f31197e6e796da6d6cc1490647f85ebb4a7179a /Lib/test/test_io.py
parent7fc972a2aa041a978b8c4b1b58d6406100a2db8d (diff)
parent94dc6736bd4a72e9af36d4df1c337bd0db5fd69c (diff)
downloadcpython-d03ce4ae3d71ba84e1e30cf0cf221ec89ad5aa67.zip
cpython-d03ce4ae3d71ba84e1e30cf0cf221ec89ad5aa67.tar.gz
cpython-d03ce4ae3d71ba84e1e30cf0cf221ec89ad5aa67.tar.bz2
Issue #17106: Fix a segmentation fault in io.TextIOWrapper when an underlying
stream or a decoder produces data of an unexpected type (i.e. when io.TextIOWrapper initialized with text stream or use bytes-to-bytes codec).
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 1cf0527..57b22c6 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2542,6 +2542,30 @@ class TextIOWrapperTest(unittest.TestCase):
txt.write('5')
self.assertEqual(b''.join(raw._write_stack), b'123\n45')
+ def test_read_nonbytes(self):
+ # Issue #17106
+ # Crash when underlying read() returns non-bytes
+ t = self.TextIOWrapper(self.StringIO('a'))
+ self.assertRaises(TypeError, t.read, 1)
+ t = self.TextIOWrapper(self.StringIO('a'))
+ self.assertRaises(TypeError, t.readline)
+ t = self.TextIOWrapper(self.StringIO('a'))
+ self.assertRaises(TypeError, t.read)
+
+ def test_illegal_decoder(self):
+ # Issue #17106
+ # Crash when decoder returns non-string
+ t = self.TextIOWrapper(self.BytesIO(b'aaaaaa'), newline='\n',
+ encoding='quopri_codec')
+ self.assertRaises(TypeError, t.read, 1)
+ t = self.TextIOWrapper(self.BytesIO(b'aaaaaa'), newline='\n',
+ encoding='quopri_codec')
+ self.assertRaises(TypeError, t.readline)
+ t = self.TextIOWrapper(self.BytesIO(b'aaaaaa'), newline='\n',
+ encoding='quopri_codec')
+ self.assertRaises(TypeError, t.read)
+
+
class CTextIOWrapperTest(TextIOWrapperTest):
def test_initialization(self):