[php-src] master: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Sat, 07 Nov 2026 11:34:57 +0000
Subject: [php-src] master: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143383@lists.php.net to get a copy of this message
Author: Jakub Zelenka (bukka) Date: 2026-11-07T12:30:40+01:00 Commit: https://github.com/php/php-src/commit/b2e02ccba0b6a87fadd99830b13440897de7e7e4 Raw diff: https://github.com/php/php-src/commit/b2e02ccba0b6a87fadd99830b13440897de7e7e4.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: 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 4f3a6607e763..053bd8f71693 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,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) 19 Nov 2026, PHP 8.5.13 diff --git a/ext/standard/file.c b/ext/standard/file.c index 381618d4f5f0..51258be9c736 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -840,6 +840,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); + } + FG(pclose_wait) = 1; zend_list_close(stream->res); FG(pclose_wait) = 0; 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 (#143383) next »