[php-src] Issue #12060: internal iterator rewind handler is called twice
| From: | ju1ius | Date: | Sun, 27 Aug 2023 16:49:09 +0000 |
| Subject: | [php-src] Issue #12060: internal iterator rewind handler is called twice | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245261@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12060
Author: ju1ius
### Description
Hi,
The
InternalIterator class (in zend_interfaces.c) uses an internal
rewind_called flag to ensure that internal iterators are always rewound. This flag is
checked by the zend_internal_iterator_ensure_rewound function, in the following
methods:
* InternalIterator::current()
* InternalIterator::key()
* InternalIterator::next()
* InternalIterator::valid()
However, in the InternalIterator::rewind() method, the rewind_called flag
is not properly set when the iterator has a rewind handler. As a result, the internal
iterator's rewind handler is always called twice on first iteration.
This is problematic since internal iterators can perform potentially heavy initialization logic in
the rewind handler (like performing a query in the case of a database result-set
iterator).
### PHP Version
PHP 8.3-dev
### Operating System
irrelevant