-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-143689: Fix BufferedReader.read1 leaving object in reentrant state on error #143690
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
base: main
Are you sure you want to change the base?
Changes from all commits
c59aa74
b8f4dcf
c751d7a
5956576
bab615a
544a44d
fbad9a2
e36ddf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| from collections import deque, UserList | ||
| from itertools import cycle, count | ||
| from test import support | ||
| from test.support import check_sanitizer | ||
| from test.support import os_helper, threading_helper | ||
| from .utils import byteslike, CTestCase, PyTestCase | ||
|
|
||
|
|
@@ -623,6 +624,25 @@ def test_bad_readinto_type(self): | |
| bufio.readline() | ||
| self.assertIsInstance(cm.exception.__cause__, TypeError) | ||
|
|
||
| @unittest.skipUnless(sys.maxsize > 2**32, 'requires 64bit platform') | ||
| @unittest.skipIf(check_sanitizer(thread=True), | ||
| 'ThreadSanitizer aborts on huge allocations (exit code 66).') | ||
| def test_read1_error_does_not_cause_reentrant_failure(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. I don’t think |
||
| self.addCleanup(os_helper.unlink, os_helper.TESTFN) | ||
| with self.open(os_helper.TESTFN, "wb") as f: | ||
| f.write(b"hello") | ||
|
|
||
| with self.open(os_helper.TESTFN, "rb", buffering=0) as raw: | ||
| bufio = self.tp(raw, buffer_size=8) | ||
| # To request a size that is far too huge to ever be satisfied, | ||
| # so that the internal buffer allocation reliably fails with MemoryError. | ||
| huge = sys.maxsize // 2 + 1 | ||
| with self.assertRaises(MemoryError): | ||
| bufio.read1(huge) | ||
|
|
||
| # Used to crash before gh-143689: | ||
| self.assertEqual(bufio.read1(1), b"h") | ||
hyongtao-code marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class PyBufferedReaderTest(BufferedReaderTest, PyTestCase): | ||
| tp = pyio.BufferedReader | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix :meth:`io.BufferedReader.read1` state cleanup on buffer allocation failure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will other sanitizers work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the
non-free-threaded TSanbuild failed; theUBSanandfree-threaded TSanbuilds are both OK.Please refer to https://github.com/python/cpython/actions/runs/20896527108/job/60035968975?pr=143690