]> granicus.if.org Git - python/commitdiff
Fix FileIO.readall() (new_buffersize()) for large files
authorVictor Stinner <victor.stinner@haypocalc.com>
Tue, 11 Oct 2011 21:00:31 +0000 (23:00 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Tue, 11 Oct 2011 21:00:31 +0000 (23:00 +0200)
Truncate the buffer size to PY_SSIZE_T_MAX.

Modules/_io/fileio.c

index dc5945504da89cbbc3f46a306f370ac9bf4e5ffe..ba5e0960297c12e7530dd7d97c9db2af4487cbb6 100644 (file)
@@ -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