Skip to content

bpo-25455: Fixed crashes in repr of recursive buffered file-like obje… #722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Lib/test/test_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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
Expand Down Expand Up @@ -176,6 +176,12 @@ def testReprNoCloseFD(self):
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())
Expand Down
20 changes: 20 additions & 0 deletions Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,16 @@ def test_repr(self):
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.
Expand Down Expand Up @@ -2424,6 +2434,16 @@ def test_repr(self):
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)
Expand Down
Loading