[issue37696] FileIO.read() on a closed TTY throws an exception prematurely

David Wilson report at bugs.python.org
Fri Aug 9 00:49:36 EDT 2019


David Wilson <dw at botanicus.net> added the comment:

A real example of where returning the partial buffer is dangerous would be EBADF.

- Repeated reading succeeds, building up a partial buffer. Another thread runs, and buggy code causes an unrelated fd blonging to the file object to be closed.

- Original thread resumes, calls read(), which now returns EBADF.

If partial buffer is returned and EBADF is masked, and user only ever calls readall() once, a potentially deadly IO corruption bug is completely hidden in their code.

I think the correct behaviour in the case of 'bad' errno must remain that the partial buffer is discarded, the interface does not seem to make room for any safe+better option


So I think to reach the desired outcome of this ticket, the suggested approach is to add special handling for a small list of errnos generally accepted to unambiguously mean EOF, and in that special case, allow returning the 'partial' (actually complete) buffer.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37696>
_______________________________________


More information about the Python-bugs-list mailing list