Skip to content

Commit ce4c8ab

Browse files
committed
Merge branch 'PHP-8.3'
2 parents 47feb57 + 4dad74f commit ce4c8ab

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

ext/standard/tests/file/file_put_contents_5gb.phpt renamed to ext/standard/tests/file/file_get_contents_file_put_contents_5gb.phpt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Test file_put_contents() function with 5GB string
2+
Test file_put_contents() and file_get_contents() functions with 5GB string
33
--SKIPIF--
44
<?php
55
if (PHP_INT_SIZE < 5) {
@@ -30,7 +30,7 @@ function get_system_memory(): int|float|false
3030
if (get_system_memory() < 10 * 1024 * 1024 * 1024) {
3131
die('skip Reason: Insufficient RAM (less than 10GB)');
3232
}
33-
$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin";
33+
$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "file_get_contents_file_put_contents_5gb.bin";
3434
$tmpfileh = fopen($tmpfile, "wb");
3535
if ($tmpfileh === false) {
3636
die('skip Reason: Unable to create temporary file');
@@ -45,23 +45,36 @@ if (disk_free_space(dirname($tmpfile)) < 10 * 1024 * 1024 * 1024) {
4545
memory_limit=6G
4646
--FILE--
4747
<?php
48-
$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin";
49-
$large_string = str_repeat('a', 5 * 1024 * 1024 * 1024);
48+
$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "file_get_contents_file_put_contents_5gb.bin";
49+
$large_string_len = 5 * 1024 * 1024 * 1024;
50+
51+
$large_string = str_repeat('a', $large_string_len);
5052
$result = file_put_contents($tmpfile, $large_string);
51-
if ($result !== strlen($large_string)) {
52-
echo "Could only write $result bytes of " . strlen($large_string) . " bytes.";
53+
if ($result !== $large_string_len) {
54+
echo "Could only write $result bytes of $large_string_len bytes.";
5355
var_dump(error_get_last());
5456
} else {
55-
echo "File written successfully.";
57+
echo "File written successfully." . PHP_EOL;
5658
}
59+
unset($large_string);
60+
61+
$result_large_string = file_get_contents($tmpfile);
62+
if (strlen($result_large_string) !== $large_string_len) {
63+
echo "Could only read " . strlen($result_large_string) . " bytes of $large_string_len bytes.";
64+
var_dump(error_get_last());
65+
} else {
66+
echo "File read successfully." . PHP_EOL;
67+
}
68+
5769
clearstatcache(true, $tmpfile);
5870
if (file_exists($tmpfile)) {
5971
unlink($tmpfile);
6072
}
6173
?>
6274
--CLEAN--
6375
<?php
64-
@unlink(sys_get_temp_dir() . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin");
76+
@unlink(sys_get_temp_dir() . DIRECTORY_SEPARATOR . "file_get_contents_file_put_contents_5gb.bin");
6577
?>
6678
--EXPECT--
6779
File written successfully.
80+
File read successfully.

main/streams/plain_wrapper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extern int php_get_gid_by_name(const char *name, gid_t *gid);
5454
#endif
5555

5656
#if defined(PHP_WIN32)
57-
# define PLAIN_WRAP_BUF_SIZE(st) (((st) > UINT_MAX) ? UINT_MAX : (unsigned int)(st))
57+
# define PLAIN_WRAP_BUF_SIZE(st) ((unsigned int)(st > INT_MAX ? INT_MAX : st))
5858
#define fsync _commit
5959
#define fdatasync fsync
6060
#else
@@ -354,7 +354,7 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
354354

355355
if (data->fd >= 0) {
356356
#ifdef PHP_WIN32
357-
ssize_t bytes_written = _write(data->fd, buf, (unsigned int)(count > INT_MAX ? INT_MAX : count));
357+
ssize_t bytes_written = _write(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count));
358358
#else
359359
ssize_t bytes_written = write(data->fd, buf, count);
360360
#endif

0 commit comments

Comments
 (0)