Skip to content

internal iterator rewind handler is called twice #12060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ju1ius opened this issue Aug 27, 2023 · 0 comments
Closed

internal iterator rewind handler is called twice #12060

ju1ius opened this issue Aug 27, 2023 · 0 comments

Comments

@ju1ius
Copy link
Contributor

ju1ius commented Aug 27, 2023

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:

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

ju1ius added a commit to ju1ius/php-src that referenced this issue Aug 27, 2023
ju1ius added a commit to ju1ius/php-src that referenced this issue Aug 27, 2023
ju1ius added a commit to ju1ius/php-src that referenced this issue Aug 27, 2023
ju1ius added a commit to ju1ius/php-src that referenced this issue Aug 27, 2023
ju1ius added a commit to ju1ius/php-src that referenced this issue Aug 27, 2023
ju1ius added a commit to ju1ius/php-src that referenced this issue Aug 27, 2023
ju1ius added a commit to ju1ius/php-src that referenced this issue Sep 2, 2023
ju1ius added a commit to ju1ius/php-src that referenced this issue Sep 2, 2023
ju1ius added a commit to ju1ius/php-src that referenced this issue Sep 5, 2023
ju1ius added a commit to ju1ius/php-src that referenced this issue Sep 5, 2023
ju1ius added a commit to ju1ius/php-src that referenced this issue Sep 5, 2023
ju1ius added a commit to ju1ius/php-src that referenced this issue Sep 5, 2023
Girgias pushed a commit that referenced this issue Sep 5, 2023
Signed-off-by: George Peter Banyard <girgias@php.net>
@Girgias Girgias closed this as completed in da7a66d Sep 5, 2023
Girgias added a commit that referenced this issue Sep 5, 2023
* PHP-8.1:
  Prevents double call to internal iterator rewind handler
  adds failing test case for #12060
Girgias added a commit that referenced this issue Sep 5, 2023
* PHP-8.2:
  Prevents double call to internal iterator rewind handler
  adds failing test case for #12060
Girgias added a commit that referenced this issue Sep 5, 2023
* PHP-8.3:
  Prevents double call to internal iterator rewind handler
  adds failing test case for #12060
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant