[Python-checkins] cpython: Fix FileIO.readall() (new_buffersize()) for large files

victor.stinner python-checkins at python.org
Tue Oct 11 23:01:14 CEST 2011


http://hg.python.org/cpython/rev/370e3472958f
changeset:   72873:370e3472958f
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Tue Oct 11 23:00:31 2011 +0200
summary:
  Fix FileIO.readall() (new_buffersize()) for large files

Truncate the buffer size to PY_SSIZE_T_MAX.

files:
  Modules/_io/fileio.c |  6 +++++-
  1 files changed, 5 insertions(+), 1 deletions(-)


diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -564,7 +564,11 @@
         */
         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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list