Skip to content

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

Closed

Description

@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
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)

Activity

  1. added 2 commits that reference this issue on Oct 29, 2026
  2. added a commit that references this issue on Oct 29, 2026
    3726b92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions