Skip to content

Fix leak of preserved input string with FILTER_THROW_ON_FAILURE#22339

Open
iliaal wants to merge 1 commit into
php:PHP-8.5from
iliaal:fix-filter-throw-leak
Open

Fix leak of preserved input string with FILTER_THROW_ON_FAILURE#22339
iliaal wants to merge 1 commit into
php:PHP-8.5from
iliaal:fix-filter-throw-leak

Conversation

@iliaal

@iliaal iliaal commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

php_zval_filter() copies the filtered value to quote it in the FilterFailedException message, then released the copy with zend_string_delref(), which only decrements the refcount. When the input is a non-string scalar that convert_to_string() turns into a fresh heap string, the copy is the sole owner and leaks one string per call, on both the failure and success paths. Use zend_string_release() so it is freed at refcount zero.

iliaal added a commit to iliaal/php-src that referenced this pull request Jun 16, 2026
php_zval_filter() copies the filtered value so it can be quoted in the
FilterFailedException message, then released the copy with
zend_string_delref(), which only decrements the refcount. When the input
is a non-string scalar that convert_to_string() turns into a fresh heap
string, the copy was the sole owner and leaked one string per call on
both the failure and the success path. Use zend_string_release() so it is
freed at refcount zero.

Closes phpGH-22339
@iliaal iliaal force-pushed the fix-filter-throw-leak branch from 842f3f2 to 38857bd Compare June 16, 2026 21:15
php_zval_filter() copies the filtered value so it can be quoted in the
FilterFailedException message, then released the copy with
zend_string_delref(), which only decrements the refcount. When the input
is a non-string scalar that convert_to_string() turns into a fresh heap
string, the copy was the sole owner and leaked one string per call on
both the failure and the success path. Use zend_string_release() so it is
freed at refcount zero.

Closes phpGH-22339
@iliaal iliaal force-pushed the fix-filter-throw-leak branch from 38857bd to 3489473 Compare June 16, 2026 22:17
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.

1 participant