-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
gh-143375: Fix a crash in BufferedWriter.seek when passing an object with a specially crafted __index__
#143577
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 5 commits
f9afb39
039bf41
2ae393b
d0c7ff5
f720950
d69c91b
ad20cda
a21ef45
92e3fde
5dbe999
05e9afd
e43c25f
0917ab1
276a2fb
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix a crash in the ``seek`` method of :class:`~io.BufferedWriter` when | ||
| passing an object with a specially crafted :meth:`~object.__index__`. | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1393,6 +1393,10 @@ _io__Buffered_seek_impl(buffered *self, PyObject *targetobj, int whence) | |
| if (target == -1 && PyErr_Occurred()) | ||
| return NULL; | ||
|
|
||
| // PyNumber_AsOff_t calls user code via __index__, which | ||
| // could have closed the file. | ||
| CHECK_CLOSED(self, "seek of closed file") | ||
|
||
|
|
||
| /* SEEK_SET and SEEK_CUR are special because we could seek inside the | ||
| buffer. Other whence values must be managed without this optimization. | ||
| Some Operating Systems can provide additional values, like | ||
|
|
||
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.
Is it only BufferedWriter or other buffered streams?
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.
It's also BufferedReader and BufferedRandom since they share the same implementation. I updated the news entry and added tests!