diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 2b9c7a06298a..0b1bb2e62d84 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -215,6 +215,18 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, if (context && (tmpzval = php_stream_context_get_option(context, wrapper->wops->label, "timeout")) != NULL) { double d = zval_get_double(tmpzval); +#ifndef PHP_WIN32 + const double timeoutmax = (double) PHP_TIMEOUT_ULL_MAX / 1000000.0; +#else + const double timeoutmax = (double) LONG_MAX / 1000000.0; +#endif + + if (d > timeoutmax) { + php_stream_wrapper_log_error(wrapper, options, "timeout must be lower than " ZEND_ULONG_FMT, (zend_ulong)timeoutmax); + zend_string_release(transport_string); + php_url_free(resource); + return NULL; + } #ifndef PHP_WIN32 timeout.tv_sec = (time_t) d; timeout.tv_usec = (size_t) ((d - timeout.tv_sec) * 1000000); diff --git a/ext/standard/tests/http/gh16810.phpt b/ext/standard/tests/http/gh16810.phpt new file mode 100644 index 000000000000..4aa563b57b27 --- /dev/null +++ b/ext/standard/tests/http/gh16810.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #79265 variation: "host:" not at start of header +--INI-- +allow_url_fopen=1 +--SKIPIF-- + +--FILE-- + [ +'timeout' => PHP_INT_MIN, +], +]; +$ctx = stream_context_create($config); +var_dump(fopen($uri, "r", false, $ctx)); + +$config['http']['timeout'] = PHP_INT_MAX; +$ctx = stream_context_create($config); +var_dump(fopen($uri, "r", false, $ctx)); +?> +--EXPECTF-- +resource(%d) of type (stream) + +Warning: fopen(http://www.example.com): Failed to open stream: timeout must be lower than %d in %s on line %d +bool(false)