[php-src] Issue #21927: Use-after-free of self-freeing MultipleIterator children

From: Date: Fri, 01 May 2026 23:14:59 +0000
Subject: [php-src] Issue #21927: Use-after-free of self-freeing MultipleIterator children
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-252030@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/21927 Author: iluuu1994 ### Description Originally reported by @flex0geek. The following code: ```php <?php class FreeSelfOnRewind implements Iterator { public function __construct(private MultipleIterator $parent) {} public function rewind(): void { $this->parent->detachIterator($this); var_dump($this); } public function current(): mixed { return 0; } public function key(): mixed { return 0; } public function next(): void {} public function valid(): bool { return false; } } $mi = new MultipleIterator(); $mi->attachIterator(new FreeSelfOnRewind($mi)); $mi->rewind(); ``` Resulted in this output: ``` Use-after-free ``` The same goes for various other MultipleIterator methods that call methods on the child iterator without addref. ### PHP Version ```plain 8.4+ ``` ### Operating System _No response_

« previous php.bugs (#252030) next »