Skip to content

[2.7] bpo-27195: Fix crashes in io.BufferedReader() and io.BufferedWriter() - #8415

Closed
ZackerySpytz wants to merge 3 commits into
python:2.7from
ZackerySpytz:bpo-27195-io-format-crashes
Closed

ZackerySpytz wants to merge 3 commits into
python:2.7from
ZackerySpytz:bpo-27195-io-format-crashes

Conversation

@ZackerySpytz

@ZackerySpytz ZackerySpytz commented Jul 23, 2018 •

Copy link
Copy Markdown
Contributor

In _bufferedreader_raw_read() and _bufferedwriter_raw_write(),
PyBUF_FORMAT should be included in the flags passed to
PyBuffer_FillInfo() (unlike in Python 3, PyMemoryView_FromBuffer()
will not set the format of the memoryview's buffer if the passed
buffer's format is NULL).

https://bugs.python.org/issue27195

…iter()

In _bufferedreader_raw_read() and _bufferedwriter_raw_write(),
PyBUF_FORMAT should be included in the flags passed to
PyBuffer_FillInfo() (unlike in Python 3, PyMemoryView_FromBuffer()
will not set the format of the memoryview's buffer if the passed
buffer's format is NULL).
@serhiy-storchaka
serhiy-storchaka self-requested a review July 23, 2018 14:33
@serhiy-storchaka serhiy-storchaka added the type-bug An unexpected behavior, bug, or error label Jul 23, 2018

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This workaround fixes the issue in this concrete case, and it looks safe enough.

But would be nice to add more details in the news entry.

@@ -0,0 +1,2 @@
Fix crashes in :class:`io.BufferedReader` and :class:`io.BufferedWriter`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a tiny bit more details.

The crash is occurred also when call tolist().

@ZackerySpytz
ZackerySpytz force-pushed the bpo-27195-io-format-crashes branch from fa3f542 to b802e44 Compare August 27, 2018 16:58
@taleinat
taleinat requested a review from skrah September 5, 2018 10:26
@taralx

taralx commented Sep 28, 2018

Copy link
Copy Markdown

I respectfully disagree with this fix. The Py_buffer documentation says that it is valid for format to be NULL, and that it means "B". So IMO the memory_format_get function just needs a NULL check in it, and to return "B" in that case.

@taralx

taralx commented Sep 28, 2018

Copy link
Copy Markdown

Created #9615 with my proposed fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants