mirror of
https://github.com/python/cpython.git
synced 2025-11-24 04:17:38 +00:00
[3.14] gh-141314: Fix TextIOWrapper.tell() assertion failure with standalone carriage return (GH-141331) (GH-141453)
Some checks are pending
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / iOS (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
Some checks are pending
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / iOS (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
The assertion was checking wrong variable (skip_back vs skip_bytes).
(cherry picked from commit af80fac425)
This commit is contained in:
parent
e9c11b7495
commit
92c14a91d2
3 changed files with 20 additions and 1 deletions
|
|
@ -3337,6 +3337,24 @@ class TextIOWrapperTest(unittest.TestCase):
|
|||
self.assertEqual(f.tell(), p1)
|
||||
f.close()
|
||||
|
||||
def test_tell_after_readline_with_cr(self):
|
||||
# Test for gh-141314: TextIOWrapper.tell() assertion failure
|
||||
# when dealing with standalone carriage returns
|
||||
data = b'line1\r'
|
||||
with self.open(os_helper.TESTFN, "wb") as f:
|
||||
f.write(data)
|
||||
|
||||
with self.open(os_helper.TESTFN, "r") as f:
|
||||
# Read line that ends with \r
|
||||
line = f.readline()
|
||||
self.assertEqual(line, "line1\n")
|
||||
# This should not cause an assertion failure
|
||||
pos = f.tell()
|
||||
# Verify we can seek back to this position
|
||||
f.seek(pos)
|
||||
remaining = f.read()
|
||||
self.assertEqual(remaining, "")
|
||||
|
||||
def test_seek_with_encoder_state(self):
|
||||
f = self.open(os_helper.TESTFN, "w", encoding="euc_jis_2004")
|
||||
f.write("\u00e6\u0300")
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
Fix assertion failure in :meth:`io.TextIOWrapper.tell` when reading files with standalone carriage return (``\r``) line endings.
|
||||
|
|
@ -2844,7 +2844,7 @@ _io_TextIOWrapper_tell_impl(textio *self)
|
|||
current pos */
|
||||
skip_bytes = (Py_ssize_t) (self->b2cratio * chars_to_skip);
|
||||
skip_back = 1;
|
||||
assert(skip_back <= PyBytes_GET_SIZE(next_input));
|
||||
assert(skip_bytes <= PyBytes_GET_SIZE(next_input));
|
||||
input = PyBytes_AS_STRING(next_input);
|
||||
while (skip_bytes > 0) {
|
||||
/* Decode up to temptative start point */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue