Skip to content

Assertion failure when freeing rvalue of ASSIGN_OBJ with typed refs and __toString() #20316

@arnaud-lb

Description

@arnaud-lb

Description

The following code:

<?php

class C {
    public string $a = '';
    public $b;
    function __toString() {
        global $c; // turns rvalue into a ref
        return '';
    }
}

$c = new C;
$c->b = &$c->a;
$c->b = $c;

Resulted in this output:

zend_execute.c:4093: i_zval_ptr_dtor_noref: Assertion `zval_get_type(&(*(zval_ptr))) != 10' failed.

Root cause is that we call zend_assign_to_variable_ex() / zend_assign_to_typed_ref_ex() with value_type=IS_TMP_VAR, when value may be a CV slot here:

variable_ptr = zend_assign_to_variable_ex(
variable_ptr, value, IS_TMP_VAR, property_uses_strict_types(), &garbage);

Therefore the slot may have been modified when reaching this call:

i_zval_ptr_dtor_noref(orig_value);

With the code above, the assertion fails because orig_value is now a ref.

PHP Version

PHP 8.3

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions