[php-src] Issue #18753: `file_get_contents()` fails with files >4GB on macOS

From: Date: Tue, 03 Jun 2025 22:32:44 +0000
Subject: [php-src] Issue #18753: `file_get_contents()` fails with files >4GB on macOS
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-250200@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/18753 Author: kiler129 ### Description ### macOS (arm64) ```php <?php ini_set('memory_limit', -1); file_get_contents("arxiv-metadata-oai-snapshot.json"); ``` Resulted in this output: ``` PHP Notice: file_get_contents(): Read of 4694832713 bytes failed with errno=22 Invalid argument in Command line code on line 1 Notice: file_get_contents(): Read of 4694832713 bytes failed with errno=22 Invalid argument in Command line code on line 1 ``` The function on macOS returns a 0-byte string: ```shell % php -dmemory_limit=-1 -r 'echo gettype(file_get_contents("arxiv-metadata-oai-snapshot.json")) . "\n";' PHP Notice: file_get_contents(): Read of 4694832713 bytes failed with errno=22 Invalid argument in Command line code on line 1 Notice: file_get_contents(): Read of 4694832713 bytes failed with errno=22 Invalid argument in Command line code on line 1 string % php -dmemory_limit=-1 -r 'echo strlen(file_get_contents("arxiv-metadata-oai-snapshot.json")) . "\n";' PHP Notice: file_get_contents(): Read of 4694832713 bytes failed with errno=22 Invalid argument in Command line code on line 1 Notice: file_get_contents(): Read of 4694832713 bytes failed with errno=22 Invalid argument in Command line code on line 1 0 ``` **Note the size reported:** it appears that macOS tries to read exactly 8,192 bytes past the file size? ``` % php -r 'echo filesize("arxiv-metadata-oai-snapshot.json") . "\n";' 4694824521 ``` ### Comparing to Linux (x86_64) On a linux system the result is different: ```shell $ php -dmemory_limit=-1 -r 'echo gettype(file_get_contents("arxiv-metadata-oai-snapshot.json")) . "\n";' string $ php -dmemory_limit=-1 -r 'echo strlen(file_get_contents("arxiv-metadata-oai-snapshot.json")) . "\n";' 4694824521 ``` ### PHP Version ```plain % php -v PHP 8.4.7 (cli) (built: May 6 2025 12:31:58) (NTS) Copyright (c) The PHP Group Built by Shivam Mathur Zend Engine v4.4.7, Copyright (c) Zend Technologies with Zend OPcache v8.4.7, Copyright (c), by Zend Technologies ``` ### Operating System macOS 15.5 (24F74)

« previous php.bugs (#250200) next »