File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -1655,6 +1655,10 @@ def readall(self):
16551655 if self ._stat_atopen is None or self ._stat_atopen .st_size <= 0 :
16561656 bufsize = DEFAULT_BUFFER_SIZE
16571657 else :
1658+ # In order to detect end of file, need a read() of at least 1
1659+ # byte which returns size 0. Oversize the buffer by 1 byte so the
1660+ # I/O can be completed with two read() calls (one for all data, one
1661+ # for EOF) without needing to resize the buffer.
16581662 bufsize = self ._stat_atopen .st_size + 1
16591663
16601664 if self ._stat_atopen .st_size > 65536 :
Original file line number Diff line number Diff line change @@ -74,6 +74,11 @@ typedef struct {
7474 signed int seekable : 2 ; /* -1 means unknown */
7575 unsigned int closefd : 1 ;
7676 char finalizing ;
77+ /* Stat result which was grabbed at file open, useful for optimizing common
78+ File I/O patterns to be more efficient. This is only guidance / an estimate,
79+ as it is subject to Time-Of-Check to Time-Of-Use (TOCTOU) issues / bugs.
80+ Both the underlying file descriptor and file may be modified outside of the
81+ fileio object / Python (ex. gh-90102, GH-121941, gh-109523). */
7782 struct _Py_stat_struct * stat_atopen ;
7883 PyObject * weakreflist ;
7984 PyObject * dict ;
You can’t perform that action at this time.
0 commit comments