Skip to content

ext/standard: stream_filter_register() orphaned user_filter_map on sh…#22838

Open
devnexen wants to merge 1 commit into
php:masterfrom
devnexen:gh22818
Open

ext/standard: stream_filter_register() orphaned user_filter_map on sh…#22838
devnexen wants to merge 1 commit into
php:masterfrom
devnexen:gh22818

Conversation

@devnexen

Copy link
Copy Markdown
Member

…utdown re-registration.

Fix GH-22818

During request shutdown the user_filter_map is torn down by the user_filters RSHUTDOWN before the streams referencing it are flushed. A user filter whose filter() callback re-registers the filter recreated the now-NULL map, then, since the volatile factory was still present in FG(stream_filters), deleted the freshly added entry and left an empty orphaned map behind. The following stream_filter_append() located the factory but no matching fdat, tripping ZEND_ASSERT(fdat), and the recreated map leaked.

Register the volatile factory first and only create and populate user_filter_map on success, so a re-registration during the shutdown window fails without recreating the map. The existing NULL-map guard in user_filter_factory_create() then handles the append gracefully.

…utdown re-registration.

Fix phpGH-22818

During request shutdown the user_filter_map is torn down by the
user_filters RSHUTDOWN before the streams referencing it are flushed. A
user filter whose filter() callback re-registers the filter recreated the
now-NULL map, then, since the volatile factory was still present in
FG(stream_filters), deleted the freshly added entry and left an empty
orphaned map behind. The following stream_filter_append() located the
factory but no matching fdat, tripping ZEND_ASSERT(fdat), and the
recreated map leaked.

Register the volatile factory first and only create and populate
user_filter_map on success, so a re-registration during the shutdown
window fails without recreating the map. The existing NULL-map guard in
user_filter_factory_create() then handles the append gracefully.
@devnexen
devnexen requested a review from bukka as a code owner July 20, 2026 20:49
@Girgias
Girgias requested a review from ndossche July 20, 2026 21:30
@Girgias

Girgias commented Jul 20, 2026

Copy link
Copy Markdown
Member

Asking Nora to have a look as she fixed a bug around this code recently.

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.

assertion failure at user_filter_factory_create

2 participants