Skip to content

PHP Crashs When Execution For Function Calls Opcodes #16138

@tahaghafuri

Description

@tahaghafuri

Description

The following code:

<?php
file_put_contents("output.txt", "This is some content to write to a file.");

Resulted in this output:
The PHP Crashs,

static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_FCALL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
    USE_OPLINE
    zval *fname;
    zval *func;
    zend_function *fbc;
    zend_execute_data *call;

    fbc = CACHED_PTR(opline->result.num);
    if (UNEXPECTED(fbc == NULL)) {
        fname = (zval*)RT_CONSTANT(opline, opline->op2);
        func = zend_hash_find_known_hash(EG(function_table), Z_STR_P(fname));
        ZEND_ASSERT(func != NULL && "Function existence must be checked at compile time");
        fbc = Z_FUNC_P(func); <<<<-- IS NULL
        if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
            init_func_run_time_cache(&fbc->op_array);
        }
        CACHE_PTR(opline->result.num, fbc);
    }

    call = _zend_vm_stack_push_call_frame_ex(
        opline->op1.num, ZEND_CALL_NESTED_FUNCTION,
        fbc, opline->extended_value, NULL);
    call->prev_execute_data = EX(call);
    EX(call) = call;

    ZEND_VM_NEXT_OPCODE();
}

image
Crash Point:
image

But I expected this output instead:

Write Sample Content To File.

Also I Think The PHP Needs Check Function Existence At Execution Time, If Not Exist Show Error.

PHP Version

PHP 8.3.12

Operating System

Windows 11

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions