From 8421cfda61cffc45efad2d6156f5042930aaa93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20W=C3=B3jcik?= Date: Fri, 12 Apr 2024 15:17:45 +0200 Subject: [PATCH] Fix file_get_contents() on Windows fails with "errno=22 Invalid argument" Closes GH-13948 --- NEWS | 4 +++ ...e_get_contents_file_put_contents_5gb.phpt} | 29 ++++++++++++++----- main/streams/plain_wrapper.c | 4 +-- 3 files changed, 27 insertions(+), 10 deletions(-) rename ext/standard/tests/file/{file_put_contents_5gb.phpt => file_get_contents_file_put_contents_5gb.phpt} (60%) diff --git a/NEWS b/NEWS index 0b50a7af1ea..b462b9b8344 100644 --- a/NEWS +++ b/NEWS @@ -41,6 +41,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 d552d86279d..854996a6481 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-- --CLEAN-- --EXPECT-- File written successfully. +File read successfully. diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index c77bd1e2415..c92b76d196d 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