[php-src] Issue #25007: Partial function application: named args in a constant expression cause out-of-bounds write in zp_compile()

From: Date: Wed, 28 Oct 2026 16:21:09 +0000
Subject: [php-src] Issue #25007: Partial function application: named args in a constant expression cause out-of-bounds write in zp_compile()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-253898@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/25007 Author: apoc ### Description zend_compile_args_ex() records named_positions only for named *placeholders*, but zend_ast_evaluate_arg_list() (Zend/zend_ast.c ~L704) records *every* named argument. zp_compile() (Zend/zend_partial.c ~L771-776, L861) uses the stored index to write into params, which is allocated with num_params elements, so params[param_offset] is written past the array and params[0] stays NULL. The following code: ```php <?php function h($a, $b = 2) {} const C = h(a: 1, b: ?); var_dump(C); ``` Resulted in this output: ``` <access violation, exit code 0xC0000005, no output> ``` But I expected this output instead: a partial function object (the same code inside a function body works), or a compile error. A parameter without a default (function g($a, $b)) gives ArgumentCountError first, so the parameter after the placeholder needs a default to reach the write. Only master/PHP-8.6 is affected (feature not yet released). Suggested fix: add the named_positions entry only when the argument is a placeholder, mirroring zend_compile_args_ex(). The existing constexpr_*.phpt mixed-argument test trips the by-reference check first, so a f(a: 1, b: ?) case should be added. ### PHP Version ``` PHP 8.7.0-dev (cli) (built: Oct 27 2026 17:51:17) (ZTS Visual C++ 2026 x64) Zend Engine v4.7.0-dev (master @ 0af8a091eec28513a6a0b758bcb10b430ba6c6de) ``` ### Operating System Windows 11 x64 (not platform specific by source inspection)

« previous php.bugs (#253898) next »