Skip to content

Commit a6a4c3b

Browse files
committed
Fix GH-18753: file_get_contents() fails with files >=2GB on macOS & BSD
1 parent 1863014 commit a6a4c3b

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

ext/standard/tests/file/gh18753.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-18753 (file_get_contents() fails with files >=2GB on macOS & BSD)
3+
--CREDITS--
4+
Gregory House <[email protected]>
5+
--INI--
6+
memory_limit=-1
7+
--SKIPIF--
8+
<?php
9+
if (PHP_OS_FAMILY !== 'Darwin' && PHP_OS_FAMILY !== 'BSD') die('skip is not macOS or BSD');
10+
if (PHP_INT_SIZE !== 8) die("skip 64-bit only");
11+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
12+
?>
13+
--FILE--
14+
<?php
15+
$fp = fopen('bigfile', 'w');
16+
ftruncate($fp, 2 * 1024 * 1024 * 1024);
17+
fclose($fp);
18+
19+
echo strlen(file_get_contents('bigfile'));
20+
?>
21+
--CLEAN--
22+
<?php
23+
unlink('bigfile');
24+
?>
25+
--EXPECT--
26+
2147483648

main/streams/plain_wrapper.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ extern int php_get_uid_by_name(const char *name, uid_t *uid);
5353
extern int php_get_gid_by_name(const char *name, gid_t *gid);
5454
#endif
5555

56-
#if defined(PHP_WIN32)
56+
#if defined(PHP_WIN32) || defined(__APPLE__) || defined(__MACH__) || defined(BSD) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
5757
# define PLAIN_WRAP_BUF_SIZE(st) ((unsigned int)(st > INT_MAX ? INT_MAX : st))
58+
#else
59+
# define PLAIN_WRAP_BUF_SIZE(st) (st)
60+
#endif
61+
62+
#if defined(PHP_WIN32)
5863
#define fsync _commit
5964
#define fdatasync fsync
6065
#else
61-
# define PLAIN_WRAP_BUF_SIZE(st) (st)
6266
# if !defined(HAVE_FDATASYNC)
6367
# define fdatasync fsync
6468
# elif defined(__APPLE__)

0 commit comments

Comments
 (0)