diff options
author | Stéphane Wirtel <stephane@wirtel.be> | 2018-10-17 23:52:21 (GMT) |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2018-10-17 23:52:21 (GMT) |
commit | a5ebc205beea2bf1501e4ac33ed6e81732dd0604 (patch) | |
tree | 5536228313290dd17c74cbb870af15caf4e03293 /Python/fileutils.c | |
parent | 669fa8b6376ee8703ae4383536dfcc0e96e51b78 (diff) | |
download | cpython-a5ebc205beea2bf1501e4ac33ed6e81732dd0604.zip cpython-a5ebc205beea2bf1501e4ac33ed6e81732dd0604.tar.gz cpython-a5ebc205beea2bf1501e4ac33ed6e81732dd0604.tar.bz2 |
[3.6] bpo-24658: Fix read/write greater than 2 GiB on macOS (GH-1705) (GH-9937)
On macOS, fix reading from and writing into a file with a size larger than 2 GiB.
(cherry picked from commit 74a8b6ea7e0a8508b13a1c75ec9b91febd8b5557)
Diffstat (limited to 'Python/fileutils.c')
-rw-r--r-- | Python/fileutils.c | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c index b8e4891..306838e 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -1263,18 +1263,9 @@ _Py_read(int fd, void *buf, size_t count) * handler raised an exception. */ assert(!PyErr_Occurred()); -#ifdef MS_WINDOWS - if (count > INT_MAX) { - /* On Windows, the count parameter of read() is an int */ - count = INT_MAX; - } -#else - if (count > PY_SSIZE_T_MAX) { - /* if count is greater than PY_SSIZE_T_MAX, - * read() result is undefined */ - count = PY_SSIZE_T_MAX; + if (count > _PY_READ_MAX) { + count = _PY_READ_MAX; } -#endif _Py_BEGIN_SUPPRESS_IPH do { @@ -1325,15 +1316,10 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held) depending on heap usage). */ count = 32767; } - else if (count > INT_MAX) - count = INT_MAX; -#else - if (count > PY_SSIZE_T_MAX) { - /* write() should truncate count to PY_SSIZE_T_MAX, but it's safer - * to do it ourself to have a portable behaviour. */ - count = PY_SSIZE_T_MAX; - } #endif + if (count > _PY_WRITE_MAX) { + count = _PY_WRITE_MAX; + } if (gil_held) { do { |