Skip to content

Fix leak of preserved input string with FILTER_THROW_ON_FAILURE#92

Closed
iliaal wants to merge 3 commits into
PHP-8.5from
fix-filter-throw-leak
Closed

Fix leak of preserved input string with FILTER_THROW_ON_FAILURE#92
iliaal wants to merge 3 commits into
PHP-8.5from
fix-filter-throw-leak

Conversation

@iliaal

@iliaal iliaal commented Jun 16, 2026

Copy link
Copy Markdown
Owner

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 iliaal force-pushed the fix-filter-throw-leak branch from 3dd4b3e to 020bb7e Compare June 16, 2026 20:00
@iliaal iliaal force-pushed the fix-filter-throw-leak branch from 020bb7e to 842f3f2 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 commented Jun 16, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#22339.

@iliaal iliaal force-pushed the fix-filter-throw-leak branch from 842f3f2 to 38857bd Compare June 16, 2026 21:15
@iliaal iliaal closed this Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants