Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5af773

Browse files
author
Victor Stinner
committed
Fix FileIO.readall() (new_buffersize()) for large files
Truncate the buffer size to PY_SSIZE_T_MAX.
1 parent 950468e commit c5af773

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Modules/_io/fileio.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,11 @@ new_buffersize(fileio *self, size_t currentsize
564564
*/
565565
if (end >= SMALLCHUNK && end >= pos && pos >= 0) {
566566
/* Add 1 so if the file were to grow we'd notice. */
567-
return currentsize + end - pos + 1;
567+
Py_off_t bufsize = currentsize + end - pos + 1;
568+
if (bufsize < PY_SSIZE_T_MAX)
569+
return (size_t)bufsize;
570+
else
571+
return PY_SSIZE_T_MAX;
568572
}
569573
}
570574
#endif

0 commit comments

Comments
 (0)