-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
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 all commits
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__`. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, a specially crafted |
||
| 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") | ||
|
Comment on lines
+1396
to
+1398
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think this comment is needed. It is trivial if we do all right, and we do not what to add such comments for each second line. Remove
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, and |
||
|
|
||
| /* 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?