Skip to content

Keep context in filtered streams #15156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
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: 1 addition & 1 deletion ext/standard/php_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
return NULL;
}

if (!(stream = php_stream_open_wrapper(p + 10, mode, options, opened_path))) {
if (!(stream = php_stream_open_wrapper_ex(p + 10, mode, options, opened_path, context))) {
efree(pathdup);
return NULL;
}
Expand Down
37 changes: 37 additions & 0 deletions ext/standard/tests/streams/gh15155.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
GH-15155: Stream context is lost when custom stream wrapper is being filtered
--FILE--
<?php

class DummyWrapper
{
public $context;

public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool
{
$options = stream_context_get_options($this->context);
var_dump($options['dummy']['foo']);
return true;
}

public function stream_stat()
{
}

public function stream_read()
{
}

public function stream_eof()
{
}
}

$context = stream_context_create(['dummy' => ['foo' => 'bar']]);
stream_wrapper_register('dummy', DummyWrapper::class);
file_get_contents('dummy://foo', false, $context);
@file_get_contents('php://filter/resource=dummy://foo', false, $context);
?>
--EXPECT--
string(3) "bar"
string(3) "bar"
Loading