[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Actually such flag already exists. It is unlocked_count. There is also similar issue with seek(). -- ___ Python tracker ___

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- pull_requests: +3661 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread Guido van Rossum
Guido van Rossum added the comment: > Why not simply document the fact that read ahead in Python 2.7 > is not thread-safe and leave it at that ? Program bugs should not crash the interpreter. (ctypes excepted.) -- ___ Python tracker

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread Marc-Andre Lemburg
Marc-Andre Lemburg added the comment: Ah, didn't see Benjamin's patch: much better solution :-) -- ___ Python tracker ___ ___ Python-

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread Marc-Andre Lemburg
Marc-Andre Lemburg added the comment: Why not simply document the fact that read ahead in Python 2.7 is not thread-safe and leave it at that ? .next() and .readline() already don't work well together, so this would just add one more case. -- nosy: +lemburg _

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread Benjamin Peterson
Changes by Benjamin Peterson : -- pull_requests: +3660 stage: -> patch review ___ Python tracker ___ ___ Python-bugs-list mailing li

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread Guido van Rossum
Guido van Rossum added the comment: @benjamin can you post your patch as a PR so you'll get credit for it? -- nosy: +gvanrossum ___ Python tracker ___ __

Re: [issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread M.-A. Lemburg
Why not simply document the fact that read ahead in Python 2.7 is not thread-safe and leave it at that ? .next() and .readline() already don't work well together, so this would just add one more case. -- Marc-Andre Lemburg eGenix.com ___ Python-bugs-l

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread STINNER Victor
STINNER Victor added the comment: @Serhiy: Would you like to propose a PR to implement your RuntimeError. Maybe we can test a few popular Python projects to see if the change would break them? Which popular applications use threads (and files)? :-) -- _

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread STINNER Victor
STINNER Victor added the comment: Serhiy: "What if just deny reentrant reads? Set a flag while read into a buffer, check it before reading in other thread, and raise RuntimeError." io.BufferedReader/io.BufferedWriter raises a RuntimeError exception for reentrant call, but only in the same thre

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread STINNER Victor
STINNER Victor added the comment: In Python 3, reading ahead is implemented by _io.BufferedReader. This object uses a lock to provide a prevent race condition: it's not only to prevent crashes, but also provide warranties on how the file is read. If thread A calls read() first, it gets the nex

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The patch is complex. What if just deny reentrant reads? Set a flag while read into a buffer, check it before reading in other thread, and raise RuntimeError. -- ___ Python tracker

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread STINNER Victor
STINNER Victor added the comment: Python 3 is not affected by this bug. In Python 3, the full I/O stack was rewritten from scratchn, the new io module has a different design. Reading ahead still exists in the io module, but it is now done by a dedicated object: io.BufferedReader, and this obje

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread STINNER Victor
STINNER Victor added the comment: The bug was first reported to the private Python security mailing list. The PSRT decided that it's a regular bug and doesn't need to be categorized as a vulnerability, since the attacker has to be able to run arbitrary code in practice. The PSRT considers tha

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread STINNER Victor
STINNER Victor added the comment: Benjamin Peterson proposed attached patch. @Benjamin: Would you mind to convert this patch to a PR to ease review? -- keywords: +patch nosy: +benjamin.peterson, serhiy.storchaka Added file: https://bugs.python.org/file47157/0001-stop-crashes-when-itera

[issue31530] [2.7] Python 2.7 readahead feature of file objects is not thread safe

2017-09-20 Thread STINNER Victor
New submission from STINNER Victor: Reading from the same file object in different threads does crash Python 2.7. The readahead feature of Objects/fileobject.c is not thread safe. Try attached script to reproduce the crash. -- components: Interpreter Core files: readahead.py messages: