[php-src] master: Merge branch 'PHP-8.6'

From: Date: Sat, 07 Nov 2026 11:34:59 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143385@lists.php.net to get a copy of this message
Author: Jakub Zelenka (bukka) Date: 2026-11-07T12:31:32+01:00 Commit: https://github.com/php/php-src/commit/ba66c154721f338b402c5625d3947663aa7978a9 Raw diff: https://github.com/php/php-src/commit/ba66c154721f338b402c5625d3947663aa7978a9.diff Merge branch 'PHP-8.6' * PHP-8.6: Fix use-after-free when pclose() closes a stream from its user filter # Conflicts: # NEWS Changed paths: A ext/standard/tests/filters/pclose_in_filter.phpt M ext/standard/file.c Diff: 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)

« previous php.cvs (#143385) next »