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
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions ext/zlib/tests/gh16883.phpt
Original file line number Diff line number Diff line change
@@ -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--
<?php
if (!file_exists(__DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc")) {
echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
}
?>
--FILE--
<?php
require __DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc";

$code = <<<'PHP'
echo $_SERVER['HTTP_USER_AGENT'], "\n";
PHP;

php_cli_server_start($code);

stream_context_set_default([
'http' => 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)
7 changes: 4 additions & 3 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading