Commit cfe29b5e13f for php

commit cfe29b5e13f99c75db95aa09a9a4220d82715d0a
Author: lacatoire <la.catoire@gmail.com>
Date:   Sat Nov 28 16:20:26 2026 +0800

    Fix stream context functions rejecting options held by reference (#25719)

    Dereference the options element of the context parameters before checking
    its type, so stream_context_create() and stream_context_set_params()
    accept references to valid options arrays. References to other types
    still raise a TypeError.

    Co-authored-by: Gina Peter Banyard <girgias@php.net>

    Closes #25719

diff --git a/NEWS b/NEWS
index 29eed216530..574b593c5fe 100644
--- a/NEWS
+++ b/NEWS
@@ -286,6 +286,8 @@ PHP                                                                        NEWS
     type on 32-bit platforms). (Kamil Tekiela)
   . Fixed bug GH-25464 (Segfault reading from php://memory after
     stream_filter_remove() on a read filter). (David Carlier)
+  . Fixed stream_context_create() and stream_context_set_params() rejecting
+    an options array passed by reference in the context parameters. (lacatoire)

 - XSL:
   . Fixed a crash in XSLTProcessor::transformToDoc() when the return class
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index d1ed12a78c3..7f10a56136c 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))) {
 		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 00000000000..d7afdd3f6f6
--- /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--
+<?php
+
+$options = ['http' => ['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