[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Jakub Zelenka | Date: | Sat, 07 Nov 2026 11:34:57 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143384@lists.php.net to get a copy of this message | ||
Author: Jakub Zelenka (bukka)
Date: 2026-11-07T12:31:12+01:00
Commit: https://github.com/php/php-src/commit/5a405e9d3ebc0e6aa2bbc27405752727468e508d
Raw diff: https://github.com/php/php-src/commit/5a405e9d3ebc0e6aa2bbc27405752727468e508d.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
Fix use-after-free when pclose() closes a stream from its user filter
# Conflicts:
# ext/standard/file.c
Changed paths:
A ext/standard/tests/filters/pclose_in_filter.phpt
M NEWS
M ext/standard/file.c
Diff:
diff --git a/NEWS b/NEWS
index f80adaa22172..a3c75a47e377 100644
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,8 @@ PHP NEWS
callback). (Ilia Alshanetsky)
. Fixed leaks and data loss when user filter leaves buckets on input
brigade. (ndossche, Matthias Goergens, Jakub Zelenka)
+ . Fixed bug GH-24175 (Use-after-free when pclose() closes a stream from its
+ user filter). (Edmond)
05 Nov 2026, PHP 8.6.0RC5
diff --git a/ext/standard/file.c b/ext/standard/file.c
index a3dd691b5d69..ff68374928c5 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -871,6 +871,11 @@ PHP_FUNCTION(pclose)
PHP_Z_PARAM_STREAM(stream)
ZEND_PARSE_PARAMETERS_END();
+ if ((stream->flags & PHP_STREAM_FLAG_NO_FCLOSE) != 0) {
+ php_error_docref(NULL, E_WARNING, "cannot close the provided stream, as it must not be
manually closed");
+ RETURN_LONG(-1);
+ }
+
php_stream_context *context = PHP_STREAM_CONTEXT(stream);
if (context) {
GC_ADDREF(context->res);
diff --git a/ext/standard/tests/filters/pclose_in_filter.phpt
b/ext/standard/tests/filters/pclose_in_filter.phpt
new file mode 100644
index 000000000000..0d13eaada0c5
--- /dev/null
+++ b/ext/standard/tests/filters/pclose_in_filter.phpt
@@ -0,0 +1,28 @@
+--TEST--
+pclose() of the stream from its user filter's callback
+--FILE--
+<?php
+class Closer extends php_user_filter {
+ public function filter($in, $out, &$consumed, bool $closing): int {
+ global $fp;
+ if (!$closing) {
+ var_dump(pclose($fp));
+ }
+ while ($bucket = stream_bucket_make_writeable($in)) {
+ $consumed += $bucket->datalen;
+ stream_bucket_append($out, $bucket);
+ }
+ return PSFS_PASS_ON;
+ }
+}
+
+stream_filter_register('closer', 'Closer');
+$fp = fopen('php://memory', 'w+');
+stream_filter_append($fp, 'closer', STREAM_FILTER_WRITE);
+fwrite($fp, 'abc');
+var_dump(pclose($fp));
+?>
+--EXPECTF--
+Warning: pclose(): cannot close the provided stream, as it must not be manually closed in %s on
line %d
+int(-1)
+int(0)