Uh oh!
There was an error while loading. Please reload this page.
- 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
Merged
+22 −1
Merged
Changes from all commits
Commits
Show all changes
9 commits Select commit Hold shift + click to select a range
c59aa74 Fix BufferedReader.read1 leaving object in reentrant state on error
hyongtao-code b8f4dcf Add test case
hyongtao-code c751d7a 📜🤖 Added by blurb_it.
blurb-it[bot] 5956576 Update test case
hyongtao-code bab615a Update Misc/NEWS.d/next/Library/2026-01-11-14-14-19.gh-issue-143689.f…
hyongtao-code 544a44d Resolved comments
hyongtao-code fbad9a2 Update Lib/test/test_io/test_bufferedio.py
hyongtao-code e36ddf6 Add comments of test case
hyongtao-code 0a11ff8 Resolve comments
hyongtao-code File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -10,7 +10,7 @@ | ||
| from collections import deque, UserList | ||
| from itertools import cycle, count | ||
| from test import support | ||
| from test.support import os_helper, threading_helper | ||
| from test.support import check_sanitizer, os_helper, threading_helper | ||
| from .utils import byteslike, CTestCase, PyTestCase | ||
| @@ -623,6 +623,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), | ||
sobolevn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| 'ThreadSanitizer aborts on huge allocations (exit code 66).') | ||
| def test_read1_error_does_not_cause_reentrant_failure(self): | ||
sobolevn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| 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 resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| class PyBufferedReaderTest(BufferedReaderTest, PyTestCase): | ||
| tp = pyio.BufferedReader | ||
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/Library/2026-01-11-14-14-19.gh-issue-143689.fzHJ2W.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix :meth:`io.BufferedReader.read1` state cleanup on buffer allocation failure. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.