diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-02-03 15:09:17 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-02-03 15:09:17 (GMT) |
commit | cce1b8eda8b697e68cb7233332f110a6a7a684a2 (patch) | |
tree | 10c6e87725f5bf41fd5a990dea7146de77624c39 /Lib/test/test_io.py | |
parent | cd50108341ca4a8e78bf57f2b64b02f7526e8166 (diff) | |
parent | d03ce4ae3d71ba84e1e30cf0cf221ec89ad5aa67 (diff) | |
download | cpython-cce1b8eda8b697e68cb7233332f110a6a7a684a2.zip cpython-cce1b8eda8b697e68cb7233332f110a6a7a684a2.tar.gz cpython-cce1b8eda8b697e68cb7233332f110a6a7a684a2.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.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 8727dde..5fe4a8d 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -2550,6 +2550,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): |