From: Victor Stinner Date: Tue, 11 Oct 2011 21:00:31 +0000 (+0200) Subject: Fix FileIO.readall() (new_buffersize()) for large files X-Git-Tag: v3.3.0a1~1214 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c5af7730e34f15d917730c66076125d4e545f11a;p=python Fix FileIO.readall() (new_buffersize()) for large files Truncate the buffer size to PY_SSIZE_T_MAX. --- diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index dc5945504d..ba5e096029 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -564,7 +564,11 @@ new_buffersize(fileio *self, size_t currentsize */ if (end >= SMALLCHUNK && end >= pos && pos >= 0) { /* Add 1 so if the file were to grow we'd notice. */ - return currentsize + end - pos + 1; + Py_off_t bufsize = currentsize + end - pos + 1; + if (bufsize < PY_SSIZE_T_MAX) + return (size_t)bufsize; + else + return PY_SSIZE_T_MAX; } } #endif