| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b618731 commit db81df6
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,7 @@ | |||
| 12 | 12 | import pickle | |
| 13 | 13 | import sys | |
| 14 | 14 | import weakref | |
| 15 | + from test.support.import_helper import import_module | ||
| 15 | 16 | ||
| 16 | 17 | class IntLike: | |
| 17 | 18 | def __init__(self, num): | |
@@ -552,6 +553,17 @@ def test_relative_seek(self): | |||
| 552 | 553 | memio.seek(1, 1) | |
| 553 | 554 | self.assertEqual(memio.read(), buf[1:]) | |
| 554 | 555 | ||
| 556 | + def test_issue141311(self): | ||
| 557 | + _testcapi = import_module("_testcapi") | ||
| 558 | + | ||
| 559 | + memio = self.ioclass() | ||
| 560 | + # Seek should allow PY_SSIZE_T_MAX, read should be capped to buffer size. | ||
| 561 | + # Past end of buffer read should always return empty bytes (EOF). | ||
| 562 | + self.assertEqual(_testcapi.PY_SSIZE_T_MAX, | ||
| 563 | + memio.seek(_testcapi.PY_SSIZE_T_MAX)) | ||
| 564 | + buf = bytearray(2) | ||
| 565 | + self.assertEqual(0, memio.readinto(buf)) | ||
| 566 | + | ||
| 555 | 567 | def test_unicode(self): | |
| 556 | 568 | memio = self.ioclass() | |
| 557 | 569 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Fix assertion failure in :class:`io.BytesIO` implementation of | ||
| 2 | + :func:`~io.BufferedIOBase.readinto` when the current offset is at the max | ||
| 3 | + offset and readinto is called. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -609,8 +609,9 @@ _io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer) | |||
| 609 | 609 | n = self->string_size - self->pos; | |
| 610 | 610 | if (len > n) { | |
| 611 | 611 | len = n; | |
| 612 | - if (len < 0) | ||
| 613 | - len = 0; | ||
| 612 | + if (len < 0) { | ||
| 613 | + return PyLong_FromSsize_t(0); | ||
| 614 | + } | ||
| 614 | 615 | } | |
| 615 | 616 | ||
| 616 | 617 | assert(self->pos + len < PY_SSIZE_T_MAX); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments