From 8fbdf98a0036a88ac204419201a0c2e6058fbd9e Mon Sep 17 00:00:00 2001 From: Quentin Dreyer Date: Mon, 29 Jul 2024 17:47:17 +0200 Subject: [PATCH 1/2] fix: keep context in filtered streams --- ext/standard/php_fopen_wrapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index a5581d9cccbe6..ea33ba4904346 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -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; } From f0319b57c5945b1e7996fdf4a02872ed1ec33c15 Mon Sep 17 00:00:00 2001 From: qkdreyer Date: Mon, 29 Jul 2024 20:48:59 +0200 Subject: [PATCH 2/2] test: keep context in filtered streams --- ext/standard/tests/streams/gh15155.phpt | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ext/standard/tests/streams/gh15155.phpt diff --git a/ext/standard/tests/streams/gh15155.phpt b/ext/standard/tests/streams/gh15155.phpt new file mode 100644 index 0000000000000..66953c85a2929 --- /dev/null +++ b/ext/standard/tests/streams/gh15155.phpt @@ -0,0 +1,37 @@ +--TEST-- +GH-15155: Stream context is lost when custom stream wrapper is being filtered +--FILE-- +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"