-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-60107: avoid io.RawIOBase.read from reading into a temporary bytearray
#138616
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?
Conversation
…table memoryview pointing to it.
This comment was marked as resolved.
This comment was marked as resolved.
Misc/NEWS.d/next/C_API/2025-09-07-10-52-09.gh-issue-60107.dhcb2Y.rst
Outdated
Show resolved
Hide resolved
io.RawIOBase.read from reading into a temporary bytearray
|
Can you indicate how efficient this actually becomes by using |
|
While I think this addition is fine, I'm worried that it could change performances a bit. So I would appreciate if we had numbers indicating whether this changed or not the performance (you can look at https://github.com/python/pyperformance for inspiration of how to write benchmarks). By the way, avoid merging main into your branch unless it's meant to fix CI tests. And remove the NEWS entry for now. We'll add it later if needed. If possible, it would be good if we also had tests where we have a class inheriting from RawIOBase and which tries to mess with the buffer passed to |
Misc/NEWS.d/next/C_API/2025-09-07-10-52-09.gh-issue-60107.dhcb2Y.rst
Outdated
Show resolved
Hide resolved
…2Y.rst Co-authored-by: Bénédikt Tran <[email protected]>
Misc/NEWS.d/next/C_API/2025-09-07-10-52-09.gh-issue-60107.dhcb2Y.rst
Outdated
Show resolved
Hide resolved
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.
should we also consider adding some extra unit tests for this change?
|
This was already mentioned:
|
| self.assertEqual(rawio.read(2), b"") | ||
|
|
||
| def test_exact_RawIOBase(self): | ||
| rawio = self.MockRawIOWithoutRead((b"ab", b"cd")) |
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.
Maybe I wasn't precise enough. RawIOBase.read() is implemented in terms of readinto. So, what we want to do is provide a readinto method that does something bad as it's given the internal buffer we constructed in C. I don't know if it's possible to cause a segfault on main with that approach though.
Stated otherwise, we want some class:
class EvilReadInto(MockRawIOWithoutRead):
def readinto(self, buf):
# do something bad with 'buf'And then
r = EvilReadInto(something_here)
r.read() # on main, this call should crash, but not with this patch|
I'm going to convert it into a draft until a regression can be found between main and this PR. IOW, we want to be able to do something evil with the buffer we are given in |
implements: https://github.com/python/cpython/issues/60107