Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ext/standard/tests/gh22818.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
Bug GH-22818: user_filter_factory_create assertion failure on shutdown re-registration
--FILE--
<?php

class rotate_filter_nw extends php_user_filter
{
public function filter($in, $out, &$consumed, $closing): int
{
$stream = fopen('php://memory', 'w+');
stream_filter_register("rotator_notWorking", rotate_filter_nw::class);
stream_filter_append($stream, "rotator_notWorking");

return PSFS_PASS_ON;
}
}

stream_filter_register("rotator_notWorking", rotate_filter_nw::class);

$stream = fopen('php://memory', 'w+');
stream_filter_append($stream, "rotator_notWorking");

echo "done\n";
?>
--EXPECTF--
done

Warning: stream_filter_append(): Unable to create or locate filter "rotator_notWorking" in %s on line %d
20 changes: 9 additions & 11 deletions ext/standard/user_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,13 @@ PHP_FUNCTION(stream_filter_register)
RETURN_THROWS();
}


/* Register the factory first; if that fails, don't (re)create the map,
* which would leak during shutdown re-registration. */
if (php_stream_filter_register_factory_volatile(filtername, &user_filter_factory) == FAILURE) {
RETURN_FALSE;
}

if (!BG(user_filter_map)) {
BG(user_filter_map) = (HashTable*) emalloc(sizeof(HashTable));
zend_hash_init(BG(user_filter_map), 8, NULL, (dtor_func_t) filter_item_dtor, 0);
Expand All @@ -626,17 +633,8 @@ PHP_FUNCTION(stream_filter_register)
fdat = ecalloc(1, sizeof(struct php_user_filter_data));
fdat->classname = zend_string_copy(classname);

if (zend_hash_add_ptr(BG(user_filter_map), filtername, fdat) != NULL) {
if (php_stream_filter_register_factory_volatile(filtername, &user_filter_factory) == SUCCESS) {
RETURN_TRUE;
}

zend_hash_del(BG(user_filter_map), filtername);
} else {
zend_string_release_ex(classname, 0);
efree(fdat);
}
zend_hash_add_ptr(BG(user_filter_map), filtername, fdat);

RETURN_FALSE;
RETURN_TRUE;
}
/* }}} */
Loading