diff --git a/ext/standard/tests/streams/gh25860.phpt b/ext/standard/tests/streams/gh25860.phpt new file mode 100644 index 000000000000..cf3c553cada6 --- /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-- + +--FILE-- + ['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 6954cd4bfde5..0a9413c751f4 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 e5d7ecb1b721..f24399349b7d 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 de75d2529987..afbb6c124eea 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;