diff --git a/ext/standard/tests/streams/gh15937.phpt b/ext/standard/tests/streams/gh15937.phpt new file mode 100644 index 0000000000000..db0564342b13b --- /dev/null +++ b/ext/standard/tests/streams/gh15937.phpt @@ -0,0 +1,16 @@ +--TEST-- +GH-15937 (stream overflow on timeout setting) +--SKIPIF-- + +--FILE-- + [ + 'timeout' => PHP_INT_MAX, + ], +]; +$ctx = stream_context_create($config); +var_dump(fopen("http://www.example.com", "r", false, $ctx)); +?> +--EXPECTF-- +resource(%d) of type (stream) diff --git a/main/php_network.h b/main/php_network.h index a3b7ba7ab3180..fda61b87cb4c9 100644 --- a/main/php_network.h +++ b/main/php_network.h @@ -162,7 +162,7 @@ PHPAPI int php_poll2(php_pollfd *ufds, unsigned int nfds, int timeout); /* timeval-to-timeout (for poll(2)) */ static inline int php_tvtoto(struct timeval *timeouttv) { - if (timeouttv) { + if (timeouttv && timeouttv->tv_sec >= 0 && timeouttv->tv_sec <= ((INT_MAX - 1000) / 1000)) { return (timeouttv->tv_sec * 1000) + (timeouttv->tv_usec / 1000); } return -1;