From 0d6f941e8be4ee48bb473b6b0688a943112ec7cd Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sun, 14 Jun 2026 22:29:37 +0200 Subject: [PATCH 1/2] Fix old license headers from latest stream changes --- ext/standard/io_poll.c | 12 +++++------- main/streams/php_stream_errors.h | 12 +++++------- main/streams/stream_errors.c | 12 +++++------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/ext/standard/io_poll.c b/ext/standard/io_poll.c index f01f8236d511..c500247dc8be 100644 --- a/ext/standard/io_poll.c +++ b/ext/standard/io_poll.c @@ -2,13 +2,11 @@ +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | https://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | + | This source file is subject to the Modified BSD License that is | + | bundled with this package in the file LICENSE, and is available | + | through the World Wide Web at . | + | | + | SPDX-License-Identifier: BSD-3-Clause | +----------------------------------------------------------------------+ | Author: Jakub Zelenka | +----------------------------------------------------------------------+ diff --git a/main/streams/php_stream_errors.h b/main/streams/php_stream_errors.h index c55c06e37f25..1642a6bdabd7 100644 --- a/main/streams/php_stream_errors.h +++ b/main/streams/php_stream_errors.h @@ -2,13 +2,11 @@ +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | https://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | + | This source file is subject to the Modified BSD License that is | + | bundled with this package in the file LICENSE, and is available | + | through the World Wide Web at . | + | | + | SPDX-License-Identifier: BSD-3-Clause | +----------------------------------------------------------------------+ | Authors: Jakub Zelenka | +----------------------------------------------------------------------+ diff --git a/main/streams/stream_errors.c b/main/streams/stream_errors.c index 3d7056c44d1e..72f7428594c3 100644 --- a/main/streams/stream_errors.c +++ b/main/streams/stream_errors.c @@ -2,13 +2,11 @@ +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | https://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | + | This source file is subject to the Modified BSD License that is | + | bundled with this package in the file LICENSE, and is available | + | through the World Wide Web at . | + | | + | SPDX-License-Identifier: BSD-3-Clause | +----------------------------------------------------------------------+ | Authors: Jakub Zelenka | +----------------------------------------------------------------------+ From 92128ac93fa3911bcedb6ee2656680939959965b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 14 Jun 2026 23:16:32 +0200 Subject: [PATCH 2/2] Fix stream_context_set_option() mutating the default context (#22235) Since GH-20524, _php_stream_open_wrapper_ex() attaches the context to a stream that has none, including the implicitly substituted default context. Sharing the default context by reference let a later stream_context_set_option() on the stream mutate the global default context, leaking options into every other context-less stream. Only attach explicitly provided contexts. Stream errors already fall back to the default context when the stream has none, so error handling is unaffected. --- ...am_context_set_option_no_default_leak.phpt | 29 +++++++++++++++++++ main/streams/streams.c | 7 ++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/streams/stream_context_set_option_no_default_leak.phpt diff --git a/ext/standard/tests/streams/stream_context_set_option_no_default_leak.phpt b/ext/standard/tests/streams/stream_context_set_option_no_default_leak.phpt new file mode 100644 index 000000000000..788b6d8a4676 --- /dev/null +++ b/ext/standard/tests/streams/stream_context_set_option_no_default_leak.phpt @@ -0,0 +1,29 @@ +--TEST-- +stream_context_set_option() on a context-less stream must not leak into the default context +--FILE-- + +--EXPECT-- +array(0) { +} +array(0) { +} +array(1) { + ["http"]=> + array(1) { + ["filename"]=> + string(8) "test.txt" + } +} diff --git a/main/streams/streams.c b/main/streams/streams.c index 715bbcfe0371..171748e6a08a 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -2248,7 +2248,12 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod stream->open_filename = __zend_orig_filename ? __zend_orig_filename : __zend_filename; stream->open_lineno = __zend_orig_lineno ? __zend_orig_lineno : __zend_lineno; #endif - if (stream->ctx == NULL && context != NULL && !persistent) { + /* Attach an explicitly provided context to the stream, but never the + * default context: sharing it by reference would let a later + * stream_context_set_option() on the stream mutate the global default + * context, leaking options into every other stream. Stream errors fall + * back to the default context on their own when the stream has none. */ + if (stream->ctx == NULL && context != NULL && context != FG(default_context) && !persistent) { php_stream_context_set(stream, context); } }