Commit 9e78ae27022 for php
commit 9e78ae27022dbedf88d17cb3210044401ea5f5f6
Author: David Carlier <devnexen@gmail.com>
Date: Sat Nov 28 04:28:50 2026 +0000
main/io: stream_copy_to_stream() socket timeout overflow.
A stream timeout above INT_MAX milliseconds was truncated when
converted to an int. Used php_tvtoto() which checks the range.
Fix GH-25860
Close GH-25863
diff --git a/NEWS b/NEWS
index aabbe28705b..4080f3225d1 100644
--- a/NEWS
+++ b/NEWS
@@ -329,6 +329,8 @@ PHP NEWS
type on 32-bit platforms). (Kamil Tekiela)
. Fixed stream_context_create() and stream_context_set_params() rejecting
an options array passed by reference in the context parameters. (lacatoire)
+ . Fixed bug GH-25860 (stream_copy_to_stream() socket timeout overflow).
+ (David Carlier)
- XSL:
. Fixed a crash in XSLTProcessor::transformToDoc() when the return class
diff --git a/ext/standard/tests/streams/gh25860.phpt b/ext/standard/tests/streams/gh25860.phpt
new file mode 100644
index 00000000000..cf3c553cada
--- /dev/null
+++ b/ext/standard/tests/streams/gh25860.phpt
@@ -0,0 +1,28 @@
+--TEST--
+GH-25860 (stream_copy_to_stream() from a socket with a timeout longer than INT_MAX milliseconds)
+--CREDITS--
+OmenP007
+--SKIPIF--
+<?php
+if (!function_exists('proc_open')) die('skip proc_open() not available');
+?>
+--FILE--
+<?php
+$file = tempnam(sys_get_temp_dir(), 'gh25860');
+$dest = fopen($file, 'wb');
+
+$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
+$proc = proc_open($php . ' -n -r "usleep(2000000); echo \'data\';"', [1 => ['socket']], $pipes);
+
+stream_set_timeout($pipes[1], 4294968);
+var_dump(stream_copy_to_stream($pipes[1], $dest, 4));
+
+fclose($pipes[1]);
+fclose($dest);
+proc_close($proc);
+var_dump(file_get_contents($file));
+@unlink($file);
+?>
+--EXPECT--
+int(4)
+string(4) "data"
diff --git a/main/io/php_io.c b/main/io/php_io.c
index 6954cd4bfde..0a9413c751f 100644
--- a/main/io/php_io.c
+++ b/main/io/php_io.c
@@ -101,9 +101,7 @@ static int php_io_generic_wait_for_data(php_io_fd *fd)
return 1;
}
- int timeout_ms = (fd->timeout.tv_sec == -1)
- ? -1
- : (int) (fd->timeout.tv_sec * 1000 + fd->timeout.tv_usec / 1000);
+ int timeout_ms = php_tvtoto(&fd->timeout);
int ret;
do {
diff --git a/main/io/php_io_copy_linux.c b/main/io/php_io_copy_linux.c
index e5d7ecb1b72..f24399349b7 100644
--- a/main/io/php_io_copy_linux.c
+++ b/main/io/php_io_copy_linux.c
@@ -46,14 +46,7 @@ static inline int php_io_linux_wait_for_data(php_io_fd *fd)
return 1;
}
- struct timeval *ptimeout = (fd->timeout.tv_sec == -1) ? NULL : &fd->timeout;
- int timeout_ms;
-
- if (ptimeout == NULL) {
- timeout_ms = -1;
- } else {
- timeout_ms = ptimeout->tv_sec * 1000 + ptimeout->tv_usec / 1000;
- }
+ int timeout_ms = php_tvtoto(&fd->timeout);
int ret;
do {
diff --git a/main/io/php_io_copy_windows.c b/main/io/php_io_copy_windows.c
index de75d252998..afbb6c124ee 100644
--- a/main/io/php_io_copy_windows.c
+++ b/main/io/php_io_copy_windows.c
@@ -44,12 +44,7 @@ static inline int php_io_win_wait_for_data(php_io_fd *fd)
return 1;
}
- int timeout_ms;
- if (fd->timeout.tv_sec == -1) {
- timeout_ms = -1;
- } else {
- timeout_ms = fd->timeout.tv_sec * 1000 + fd->timeout.tv_usec / 1000;
- }
+ int timeout_ms = php_tvtoto(&fd->timeout);
WSAPOLLFD pfd;
pfd.fd = fd->socket;