[php-src] PR #18755: Fix GH-18753: file_get_contents() fails with files >=2GB on macOS & BSD

From: Date: Wed, 04 Jun 2025 05:31:56 +0000
Subject: [php-src] PR #18755: Fix GH-18753: file_get_contents() fails with files >=2GB on macOS & BSD
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-31946@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/18755 Author: kiler129 ### Problem On Linux read(3) syscall returns as many bytes as possible, up to requested maximum. Darwin/XNU and BSD kernels instead [immediately returns EINVAL](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102259) if the requested value is larger than native INT_MAX. This causes file_get_contents() to fail with files larger than 2147483647 bytes. ### Fix This patch applies the same clamping of buffer/read chunk to 2GB as previously on Windows. This fixes the file_get_contents(). There's still a way to trigger the problem using fread() with stream_set_read_buffer() set to 0/unbuffered, but I think this is more of an expected behavior. After this patch the later returns with EBADF instead of EINVAL. ### Affected version The bug stems affects 8.2 onwards d/t https://github.com/php/php-src/commit/6beee1a5bb04d399518e4e4d94a4b82d367161fd from https://github.com/php/php-src/pull/8547. However, as this is not a security issue I'm targeting 8.3 as it's [latest actively supported](https://www.php.net/supported-versions) version.

« previous php.git-pulls (#31946) next »