[php-src] PR #22503: Fix GH-15836: don't expose a freed stream resource to user filters
| From: | iliaal | Date: | Sun, 28 Jun 2026 18:28:36 +0000 |
| Subject: | [php-src] PR #22503: Fix GH-15836: don't expose a freed stream resource to user filters | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-36719@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/22503
Author: iliaal
A user stream filter that reads
$this->stream during the close flush could capture
an already-freed stream resource in an exception backtrace, a use-after-free that corrupts the heap
(the reporter's php://memory reproducer aborts with "zend_mm_heap corrupted").
When _php_stream_free() runs the write-filter close flush from the resource destructor,
the resource is already dtor'd (type == -1) and about to be
efree'd, but userfilter_filter() still handed it to userland via
$this->stream. The guard exposes the resource only while it is still live and
assigns null otherwise. The explicit fclose() path flushes before
zend_list_close(), so its resource is still live and behavior there is unchanged. The
null branch intentionally skips php_stream_to_zval()'s __exposed=1
side effect, since the resource is not actually exposed.
Fixes #15836