From d28bd346d0186128bb17d7ad8d334652824e13eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ey=C3=BCp=20Can=20Akman?= Date: Thu, 5 Nov 2026 21:08:58 +0300 Subject: [PATCH] Add test for filter_var_array() leak when a nested element throws GH-25349's merge into PHP-8.5 fixed the leak by freeing the copy before the return. Covers the FILTER_THROW_ON_FAILURE and throwing callback cases. --- .../filter_var_array_exception_leak.phpt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ext/filter/tests/filter_var_array_exception_leak.phpt diff --git a/ext/filter/tests/filter_var_array_exception_leak.phpt b/ext/filter/tests/filter_var_array_exception_leak.phpt new file mode 100644 index 000000000000..49de8e3b5879 --- /dev/null +++ b/ext/filter/tests/filter_var_array_exception_leak.phpt @@ -0,0 +1,26 @@ +--TEST-- +filter_var_array() does not leak the filtered value when filtering it throws +--EXTENSIONS-- +filter +--FILE-- + ['1', 'x']], ['a' => ['filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY | FILTER_THROW_ON_FAILURE]]); +} catch (Filter\FilterFailedException $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + filter_var_array(['a' => ['1', 'x']], ['a' => ['filter' => FILTER_CALLBACK, 'options' => function ($value) { + if ($value === 'x') { + throw new Exception('callback failed'); + } + return $value; + }]]); +} catch (Exception $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +?> +--EXPECT-- +Filter\FilterFailedException: filter validation failed: filter int not satisfied by 'x' +Exception: callback failed