Skip to content

Fix GH-25415: Segfault in FilterIterator::next() after failed parent ctor - #25417

Open
lazerg wants to merge 2 commits into
php:PHP-8.4from
lazerg:fix/gh-25415
Open

lazerg wants to merge 2 commits into
php:PHP-8.4from
lazerg:fix/gh-25415

Conversation

@lazerg

@lazerg lazerg commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

When a closed generator is passed to parent::__construct() of a dual iterator, the constructor throws after the object is already marked as constructed, so inner.iterator stays NULL. If the subclass catches the exception, spl_dual_it_next() only checked for a NULL inner iterator when do_free was 0, so next() on FilterIterator, IteratorIterator, LimitIterator and friends dereferenced it. NoRewindIterator had the same problem in valid(), key(), current() and next().

The NULL check in spl_dual_it_next() now runs in both cases, and the NoRewindIterator methods behave like the other iterators here: valid() returns false, key() and current() return NULL, and next() throws the existing "inner constructor wasn't initialized" error.

Fixes #25415

@lazerg

lazerg commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

The LINUX_X32_DEBUG_ZTS Tracing JIT failure also happens on PHP-8.4 itself (runs 43196288502 and 43186660061), so it isn't caused by this change.

Comment thread ext/spl/spl_iterators.c Outdated
Comment on lines +2723 to +2726
SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS);
if (!intern->inner.iterator) {
RETURN_NULL();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This very much feels that this check should be in SPL_FETCH_AND_CHECK_DUAL_IT and not ad hoc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it into SPL_FETCH_AND_CHECK_DUAL_IT in e1cc0c7 and dropped the ad hoc checks. AppendIterator is exempt since its inner iterator is legitimately NULL until the first append.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants