diff --git a/UPGRADING b/UPGRADING index 086fb975d05df..d23cb305b26b4 100644 --- a/UPGRADING +++ b/UPGRADING @@ -155,6 +155,8 @@ PHP 8.5 UPGRADE NOTES . The "use_include_path" argument for the gzfile, gzopen and readgzfile functions had been changed from int to boolean. + . gzfile, gzopen and readgzfile functions now respect the default + stream context. ======================================== 6. New Functions diff --git a/ext/zlib/tests/gh16883.phpt b/ext/zlib/tests/gh16883.phpt new file mode 100644 index 0000000000000..c3d81d4537938 --- /dev/null +++ b/ext/zlib/tests/gh16883.phpt @@ -0,0 +1,46 @@ +--TEST-- +GH-16883 (gzopen() does not use the default stream context when opening HTTP URLs) +--EXTENSIONS-- +zlib +--INI-- +allow_url_fopen=1 +--SKIPIF-- + +--FILE-- + array( + 'user_agent' => 'dummy', + ) +]); + +$f = gzopen('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT, 'r'); +var_dump(stream_get_contents($f)); + +var_dump(gzfile('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT, 'r')); + +var_dump(readgzfile('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT, 'r')); + +?> +--EXPECT-- +string(6) "dummy +" +array(1) { + [0]=> + string(6) "dummy +" +} +dummy +int(6) diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index df3d270217d45..3a72bd506340f 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -26,6 +26,7 @@ #include "SAPI.h" #include "php_ini.h" #include "ext/standard/info.h" +#include "ext/standard/file.h" #include "php_zlib.h" #include "zlib_arginfo.h" @@ -621,7 +622,7 @@ PHP_FUNCTION(gzfile) } /* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */ - stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC); + stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, php_stream_context_from_zval(NULL, false) STREAMS_CC); if (!stream) { /* Error reporting is already done by stream code */ @@ -659,7 +660,7 @@ PHP_FUNCTION(gzopen) flags |= USE_PATH; } - stream = php_stream_gzopen(NULL, filename, mode, flags, NULL, NULL STREAMS_CC); + stream = php_stream_gzopen(NULL, filename, mode, flags, NULL, php_stream_context_from_zval(NULL, false) STREAMS_CC); if (!stream) { RETURN_FALSE; @@ -686,7 +687,7 @@ PHP_FUNCTION(readgzfile) flags |= USE_PATH; } - stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, NULL STREAMS_CC); + stream = php_stream_gzopen(NULL, filename, "rb", flags, NULL, php_stream_context_from_zval(NULL, false) STREAMS_CC); if (!stream) { RETURN_FALSE;