Skip to content

Fix leak of preserved input string with FILTER_THROW_ON_FAILURE#22339

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

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
@iliaal iliaal requested a review from DanielEScherzer June 17, 2026 18:32

@DanielEScherzer DanielEScherzer left a comment

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.

Good catch, thanks

@iliaal iliaal closed this in 235b9b5 Jun 17, 2026
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