[php-src] PHP-8.3: Merge branch 'PHP-8.2' into PHP-8.3
| From: | Jakub Zelenka | Date: | Sun, 14 Apr 2024 13:27:25 +0000 |
| Subject: | [php-src] PHP-8.3: Merge branch 'PHP-8.2' into PHP-8.3 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-128099@lists.php.net to get a copy of this message | ||
Author: Jakub Zelenka (bukka)
Date: 2024-04-14T14:27:05+01:00
Commit: https://github.com/php/php-src/commit/4dad74f250de682a7deae0c9895436cd8aee6978
Raw diff: https://github.com/php/php-src/commit/4dad74f250de682a7deae0c9895436cd8aee6978.diff
Merge branch 'PHP-8.2' into PHP-8.3
Changed paths:
A ext/standard/tests/file/file_get_contents_file_put_contents_5gb.phpt
D ext/standard/tests/file/file_put_contents_5gb.phpt
M NEWS
M main/streams/plain_wrapper.c
Diff:
diff --git a/NEWS b/NEWS
index 736fa7d4f53d6..7fe388751d76a 100644
--- a/NEWS
+++ b/NEWS
@@ -51,6 +51,10 @@ PHP NEWS
. Fixed bug GH-13891 (memleak and segfault when using ini_set with
session.trans_sid_hosts). (nielsdos, kamil-tekiela)
+- Standard:
+ . Fixed file_get_contents() on Windows fails with "errno=22 Invalid
+ argument". (Damian Wójcik)
+
- Streams:
. Fixed bug GH-13264 (Part 1 - Memory leak on stream filter failure).
(Jakub Zelenka)
diff --git a/ext/standard/tests/file/file_put_contents_5gb.phpt
b/ext/standard/tests/file/file_get_contents_file_put_contents_5gb.phpt
similarity index 60%
rename from ext/standard/tests/file/file_put_contents_5gb.phpt
rename to ext/standard/tests/file/file_get_contents_file_put_contents_5gb.phpt
index d552d86279d03..854996a6481e7 100644
--- a/ext/standard/tests/file/file_put_contents_5gb.phpt
+++ b/ext/standard/tests/file/file_get_contents_file_put_contents_5gb.phpt
@@ -1,5 +1,5 @@
--TEST--
-Test file_put_contents() function with 5GB string
+Test file_put_contents() and file_get_contents() functions with 5GB string
--SKIPIF--
<?php
if (PHP_INT_SIZE < 5) {
@@ -30,7 +30,7 @@ function get_system_memory(): int|float|false
if (get_system_memory() < 10 * 1024 * 1024 * 1024) {
die('skip Reason: Insufficient RAM (less than 10GB)');
}
-$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin";
+$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR .
"file_get_contents_file_put_contents_5gb.bin";
$tmpfileh = fopen($tmpfile, "wb");
if ($tmpfileh === false) {
die('skip Reason: Unable to create temporary file');
@@ -45,15 +45,27 @@ if (disk_free_space(dirname($tmpfile)) < 10 * 1024 * 1024 * 1024) {
memory_limit=6G
--FILE--
<?php
-$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin";
-$large_string = str_repeat('a', 5 * 1024 * 1024 * 1024);
+$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR .
"file_get_contents_file_put_contents_5gb.bin";
+$large_string_len = 5 * 1024 * 1024 * 1024;
+
+$large_string = str_repeat('a', $large_string_len);
$result = file_put_contents($tmpfile, $large_string);
-if ($result !== strlen($large_string)) {
- echo "Could only write $result bytes of " . strlen($large_string) . "
bytes.";
+if ($result !== $large_string_len) {
+ echo "Could only write $result bytes of $large_string_len bytes.";
var_dump(error_get_last());
} else {
- echo "File written successfully.";
+ echo "File written successfully." . PHP_EOL;
}
+unset($large_string);
+
+$result_large_string = file_get_contents($tmpfile);
+if (strlen($result_large_string) !== $large_string_len) {
+ echo "Could only read " . strlen($result_large_string) . " bytes of
$large_string_len bytes.";
+ var_dump(error_get_last());
+} else {
+ echo "File read successfully." . PHP_EOL;
+}
+
clearstatcache(true, $tmpfile);
if (file_exists($tmpfile)) {
unlink($tmpfile);
@@ -61,7 +73,8 @@ if (file_exists($tmpfile)) {
?>
--CLEAN--
<?php
-@unlink(sys_get_temp_dir() . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin");
+@unlink(sys_get_temp_dir() . DIRECTORY_SEPARATOR .
"file_get_contents_file_put_contents_5gb.bin");
?>
--EXPECT--
File written successfully.
+File read successfully.
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index b1d0f00f4b1fa..83a1b9fed49d5 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -54,7 +54,7 @@ extern int php_get_gid_by_name(const char *name, gid_t *gid);
#endif
#if defined(PHP_WIN32)
-# define PLAIN_WRAP_BUF_SIZE(st) (((st) > UINT_MAX) ? UINT_MAX : (unsigned int)(st))
+# define PLAIN_WRAP_BUF_SIZE(st) ((unsigned int)(st > INT_MAX ? INT_MAX : st))
#define fsync _commit
#define fdatasync fsync
#else
@@ -354,7 +354,7 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun
if (data->fd >= 0) {
#ifdef PHP_WIN32
- ssize_t bytes_written = _write(data->fd, buf, (unsigned int)(count > INT_MAX ? INT_MAX :
count));
+ ssize_t bytes_written = _write(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count));
#else
ssize_t bytes_written = write(data->fd, buf, count);
#endif