summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-19 18:27:16 (GMT)
committerGitHub <noreply@github.com>2017-03-19 18:27:16 (GMT)
commitfca705d533970011e50b3f278aab81cead39b00d (patch)
treea4ce6eab4799ba8cdaf848c70d02a18ed4ce727b /Lib/test
parent69eab3123ed1de4bed4b7dedecabe415f6139bb6 (diff)
downloadcpython-fca705d533970011e50b3f278aab81cead39b00d.zip
cpython-fca705d533970011e50b3f278aab81cead39b00d.tar.gz
cpython-fca705d533970011e50b3f278aab81cead39b00d.tar.bz2
bpo-25455: Fixed crashes in repr of recursive buffered file-like objects. (#514) (#722)
(cherry picked from commit a5af6e1af77ee0f9294c5776478a9c24d9fbab94)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_fileio.py8
-rw-r--r--Lib/test/test_io.py20
2 files changed, 27 insertions, 1 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
index 3da210a..57a0265 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -10,7 +10,7 @@ from weakref import proxy
from functools import wraps
from test.support import (TESTFN, TESTFN_UNICODE, check_warnings, run_unittest,
- make_bad_fd, cpython_only)
+ make_bad_fd, cpython_only, swap_attr)
from collections import UserList
import _io # C implementation of io
@@ -176,6 +176,12 @@ class AutoFileTests:
finally:
os.close(fd)
+ def testRecursiveRepr(self):
+ # Issue #25455
+ with swap_attr(self.f, 'name', self.f):
+ with self.assertRaises(RuntimeError):
+ repr(self.f) # Should not crash
+
def testErrors(self):
f = self.f
self.assertFalse(f.isatty())
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index aaa64ea..8f895fe 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -1014,6 +1014,16 @@ class CommonBufferedTests:
raw.name = b"dummy"
self.assertEqual(repr(b), "<%s name=b'dummy'>" % clsname)
+ def test_recursive_repr(self):
+ # Issue #25455
+ raw = self.MockRawIO()
+ b = self.tp(raw)
+ with support.swap_attr(raw, 'name', b):
+ try:
+ repr(b) # Should not crash
+ except RuntimeError:
+ pass
+
def test_flush_error_on_close(self):
# Test that buffered file is closed despite failed flush
# and that flush() is called before file closed.
@@ -2424,6 +2434,16 @@ class TextIOWrapperTest(unittest.TestCase):
t.buffer.detach()
repr(t) # Should not raise an exception
+ def test_recursive_repr(self):
+ # Issue #25455
+ raw = self.BytesIO()
+ t = self.TextIOWrapper(raw)
+ with support.swap_attr(raw, 'name', t):
+ try:
+ repr(t) # Should not crash
+ except RuntimeError:
+ pass
+
def test_line_buffering(self):
r = self.BytesIO()
b = self.BufferedWriter(r, 1000)