diff -r 777256817c1b Lib/test/test_io.py --- a/Lib/test/test_io.py Thu Aug 04 12:14:51 2016 -0500 +++ b/Lib/test/test_io.py Thu Aug 04 19:58:21 2016 +0200 @@ -561,6 +561,24 @@ with self.open(support.TESTFN, "w+b") as f: self.large_file_ops(f) + def test_large_writes(self): + support.requires('largefile', + 'test requires %s bytes and a long time to run' % self.LARGE) + with self.open(support.TESTFN, "wb") as f: + b = bytearray(self.LARGE) + self.assertEqual(f.write(b), self.LARGE) + + def test_large_reads(self): + support.requires('largefile', + 'test requires %s bytes and a long time to run' % self.LARGE) + with self.open(support.TESTFN, "wb") as f: + b = bytearray(self.LARGE) + self.assertEqual(f.write(b), self.LARGE) + + with self.open(support.TESTFN, "rb") as f: + self.assertEqual(f.read(self.LARGE), self.LARGE) + + def test_with_open(self): for bufsize in (0, 1, 100): f = None diff -r 777256817c1b Python/fileutils.c --- a/Python/fileutils.c Thu Aug 04 12:14:51 2016 -0500 +++ b/Python/fileutils.c Thu Aug 04 19:58:21 2016 +0200 @@ -1203,6 +1203,13 @@ /* On Windows, the count parameter of read() is an int */ count = INT_MAX; } +#elif defined(__APPLE__) + if (count > INT_MAX) { + /* Issue #24658: On OSX read(2) will fail when reading more than INT_MAX + * bytes. + */ + count = INT_MAX; + } #else if (count > PY_SSIZE_T_MAX) { /* if count is greater than PY_SSIZE_T_MAX, @@ -1272,6 +1279,12 @@ } else if (count > INT_MAX) count = INT_MAX; +#elif defined(__APPLE__) + if (count > INT_MAX) { + /* Issue #24658: On OSX write(2) will fail when writing more than + INT_MAX bytes. */ + count = INT_MAX; + } #else if (count > PY_SSIZE_T_MAX) { /* write() should truncate count to PY_SSIZE_T_MAX, but it's safer