diff --git a/NEWS b/NEWS index 21c7d6165d5..f53996ae660 100644 --- a/NEWS +++ b/NEWS @@ -32,6 +32,8 @@ PHP NEWS . Fixed bug GH-11808 (Live filesystem modified by tests). (nielsdos) . Fixed GH-13402 (Added validation of `\n` in $additional_headers of mail()). (SakiTakamachi) + . Fixed bug GH-13203 (file_put_contents fail on strings over 4GB on Windows). + (divinity76) - XML: . Fixed bug GH-13517 (Multiple test failures when building with diff --git a/ext/standard/tests/file/file_put_contents_5gb.phpt b/ext/standard/tests/file/file_put_contents_5gb.phpt new file mode 100644 index 00000000000..7d91ef691b5 --- /dev/null +++ b/ext/standard/tests/file/file_put_contents_5gb.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test file_put_contents() function with 5GB string +--SKIPIF-- + +--INI-- +memory_limit=6G +--FILE-- + +--CLEAN-- + +--EXPECT-- +File written successfully. diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index e9a30f33340..c77bd1e2415 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -40,6 +40,7 @@ # include "win32/time.h" # include "win32/ioutil.h" # include "win32/readdir.h" +# include #endif #define php_stream_fopen_from_fd_int(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_CC) @@ -353,11 +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; - if (ZEND_SIZE_T_UINT_OVFL(count)) { - count = UINT_MAX; - } - bytes_written = _write(data->fd, buf, (unsigned int)count); + ssize_t bytes_written = _write(data->fd, buf, (unsigned int)(count > INT_MAX ? INT_MAX : count)); #else ssize_t bytes_written = write(data->fd, buf, count); #endif