Skip to content

Assertion failure Zend/zend_hash.c:1543 #17416

Open

Description

@YuanchengJiang

Description

The following code:

<?php
function Error2Exception($errno, $errstr, $errfile, $errline)
{
throw new MyException($errstr, $errno);
}
set_error_handler('Error2Exception');
function bar(array &$a): ?bool {
foreach ($a as $key => $val) {
if ($val === 2) {
unset($a[$fusion]);
}
}
}
function foo($a, bool $b): bool {
do {
$res = bar($a);
} while ($res === null && $n !== $n2);
}
foo([2,'a'=>5], false);

Resulted in this output:

php: /home/phpfuzz/WorkSpace/flowfusion/php-src/Zend/zend_hash.c:1543: zend_result zend_hash_del(HashTable *, zend_string *): Assertion `(zend_gc_refcount(&(ht)->gc) == 1) || ((ht)->u.flags & (1<<6))' failed.
Aborted (core dumped)

PHP Version

nightly

Operating System

No response

Activity

  1. arnaud-lb commented on Jan 9, 2025

    @arnaud-lb
    Member

    Minimal reproducer:

    function Error2Exception($errno, $errstr, $errfile, $errline) {
        throw null;
    }
    
    set_error_handler('Error2Exception');
    
    function bar(array $a) {
        unset($a[$fusion]);
    }
    
    bar([2]);

    $a is separated at the beginning of ZEND_UNSET_DIM, but new references are created when collecting arguments for the exception backtrace, before actually modifying the array.

    This would be fixed by delaying error handling (#12805).

  2. added theissue type on Feb 5, 2025
  3. added a commit that references this issue on Jul 15, 2026
    c7265d4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions