# HG changeset patch # Parent ca54c27a9045c655ef1ad9ce248f02eb00137476 diff -r ca54c27a9045 -r cebb1c0e4a6f Modules/_io/fileio.c --- a/Modules/_io/fileio.c Tue Aug 21 14:54:22 2012 +0100 +++ b/Modules/_io/fileio.c Wed Aug 22 10:53:53 2012 +0100 @@ -631,27 +631,31 @@ end = (Py_off_t)-1; #endif while (1) { + if (total < PyBytes_GET_SIZE(result)) { + newsize = PyBytes_GET_SIZE(result); + } else { #ifdef HAVE_FSTAT - newsize = new_buffersize(self, total, pos, end); + newsize = new_buffersize(self, total, pos, end); #else - newsize = new_buffersize(self, total); + newsize = new_buffersize(self, total); #endif - if (newsize> PY_SSIZE_T_MAX || newsize <= 0) { - PyErr_SetString(PyExc_OverflowError, - "unbounded read returned more bytes " - "than a Python string can hold "); - Py_DECREF(result); - return NULL; - } + if (newsize> PY_SSIZE_T_MAX || newsize <= 0) { + PyErr_SetString(PyExc_OverflowError, + "unbounded read returned more bytes " + "than a Python string can hold "); + Py_DECREF(result); + return NULL; + } - if (PyBytes_GET_SIZE(result) < (Py_ssize_t)newsize) { - if (_PyBytes_Resize(&result, newsize) < 0) { - if (total == 0) { - Py_DECREF(result); - return NULL; + if (PyBytes_GET_SIZE(result) < (Py_ssize_t)newsize) { + if (_PyBytes_Resize(&result, newsize) < 0) { + if (total == 0) { + Py_DECREF(result); + return NULL; + } + PyErr_Clear(); + break; } - PyErr_Clear(); - break; } } Py_BEGIN_ALLOW_THREADS