Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ext/standard/tests/streams/gh25860.phpt
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 1 addition & 3 deletions main/io/php_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 1 addition & 8 deletions main/io/php_io_copy_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 1 addition & 6 deletions main/io/php_io_copy_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading