Repository navigation
Fix GH-24579: Validate option_array type before accessing as hash table - #24619
paezraphael wants to merge 1 commit into
Conversation
…table Calling filter_var() with FILTER_VALIDATE_INT crashed when the input object implemented __toString() and modified the options array referenced by the filter arguments during string conversion. The FETCH_*_OPTION macros checked if option_array was non-null but did not validate it was an array before using Z_ARRVAL_P(). When __toString() mutated the reference to a string, the code attempted to access it as a hash table, causing a crash (SIGSEGV in non-debug builds, assertion failure in debug builds). This commit adds a Z_TYPE_P(option_array) == IS_ARRAY check to FETCH_LONG_OPTION, FETCH_DOUBLE_OPTION, and FETCH_STRING_OPTION to ensure the type is an array before accessing as a hash table. Added regression test phpGH-24579. Fixes phpGH-24579. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Quoted below: written with Claude, an LLM, as CONTRIBUTING.md asks us to mark. The builds and test runs behind it are on my machine; the commands to repeat them are under the fold.
|
|
Closing in favor of #24580, which fixes GH-24579 as well. #24580 was opened first, targets PHP-8.4 (the lowest affected branch, per CONTRIBUTING.md), and is more complete: it holds a counted copy of the options for the whole call, so besides fixing the crash it also keeps the options as they were passed, rather than reading values mutated during Thanks @anun333 for the side-by-side testing that made the difference clear. |
Calling filter_var() with FILTER_VALIDATE_INT crashed when the input object implemented __toString() and modified the options array referenced by the filter arguments during string conversion.
The FETCH_*_OPTION macros checked if option_array was non-null but did not validate it was an array before using Z_ARRVAL_P(). When __toString() mutated the reference to a string, the code attempted to access it as a hash table, causing a crash (SIGSEGV in non-debug builds, assertion failure in debug builds).
This commit adds a Z_TYPE_P(option_array) == IS_ARRAY check to FETCH_LONG_OPTION, FETCH_DOUBLE_OPTION, and FETCH_STRING_OPTION to ensure the type is an array before accessing as a hash table.
Added regression test GH-24579.
Fixes GH-24579.
Generated with Devin