From 3800545f07ebf13ffb039313857e410d2388a0b2 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Tue, 24 Nov 2026 21:47:27 +0100 Subject: [PATCH 1/3] Fix stream_context_create() rejecting an "options" parameter held by reference --- ext/standard/streamsfuncs.c | 1 + ...tream_context_create_params_reference.phpt | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 ext/standard/tests/streams/stream_context_create_params_reference.phpt diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index d1ed12a78c3a..c4c5cb83f6cf 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -953,6 +953,7 @@ static zend_result parse_context_params(php_stream_context *context, HashTable * context->notifier->dtor = user_space_stream_notifier_dtor; } if (NULL != (tmp = zend_hash_str_find(params, "options", sizeof("options")-1))) { + ZVAL_DEREF(tmp); if (Z_TYPE_P(tmp) == IS_ARRAY) { return parse_context_options(context, Z_ARRVAL_P(tmp)); } else { diff --git a/ext/standard/tests/streams/stream_context_create_params_reference.phpt b/ext/standard/tests/streams/stream_context_create_params_reference.phpt new file mode 100644 index 000000000000..d7afdd3f6f66 --- /dev/null +++ b/ext/standard/tests/streams/stream_context_create_params_reference.phpt @@ -0,0 +1,48 @@ +--TEST-- +stream_context_create() and stream_context_set_params() accept an "options" element held by reference +--FILE-- + ['method' => 'HEAD']]; +$params = ['options' => &$options]; + +try { + $context = stream_context_create(null, $params); + var_dump(stream_context_get_options($context)); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +$context = stream_context_create(); +try { + var_dump(stream_context_set_params($context, $params)); + var_dump(stream_context_get_options($context)); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +$invalid = 'not an array'; +try { + stream_context_create(null, ['options' => &$invalid]); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +array(1) { + ["http"]=> + array(1) { + ["method"]=> + string(4) "HEAD" + } +} +bool(true) +array(1) { + ["http"]=> + array(1) { + ["method"]=> + string(4) "HEAD" + } +} +TypeError: Invalid stream/context parameter From 1edb9e17262d618aa007702c09fcb2f55c495d90 Mon Sep 17 00:00:00 2001 From: Louis-Arnaud Date: Thu, 26 Nov 2026 15:02:33 +0100 Subject: [PATCH 2/3] Update ext/standard/streamsfuncs.c Co-authored-by: Gina Peter Banyard --- ext/standard/streamsfuncs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index c4c5cb83f6cf..0da1ef7dd7b3 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -952,7 +952,7 @@ static zend_result parse_context_params(php_stream_context *context, HashTable * ZVAL_COPY(&context->notifier->ptr, tmp); context->notifier->dtor = user_space_stream_notifier_dtor; } - if (NULL != (tmp = zend_hash_str_find(params, "options", sizeof("options")-1))) { + if (NULL != (tmp = zend_hash_str_find_deref(params, "options", sizeof("options")-1))) { ZVAL_DEREF(tmp); if (Z_TYPE_P(tmp) == IS_ARRAY) { return parse_context_options(context, Z_ARRVAL_P(tmp)); From 1a303f6c3c26d1af8b7527f47d0a54c09ddc6c6c Mon Sep 17 00:00:00 2001 From: lacatoire Date: Thu, 26 Nov 2026 21:33:30 +0100 Subject: [PATCH 3/3] Remove the redundant ZVAL_DEREF() zend_hash_str_find_deref() already dereferences the value. --- ext/standard/streamsfuncs.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 0da1ef7dd7b3..7f10a56136c1 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -953,7 +953,6 @@ static zend_result parse_context_params(php_stream_context *context, HashTable * context->notifier->dtor = user_space_stream_notifier_dtor; } if (NULL != (tmp = zend_hash_str_find_deref(params, "options", sizeof("options")-1))) { - ZVAL_DEREF(tmp); if (Z_TYPE_P(tmp) == IS_ARRAY) { return parse_context_options(context, Z_ARRVAL_P(tmp)); } else {