php / php/php-src

GC Reference Counting Assertion Failure via Object Destruction and Invalid Assignment

Open
#19,999 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Category: Engine Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following php input triggers a reference counting bug in PHP's Zend garbage collector:

<?php
for ($i = 0; $a== 0; $h++) { 
    $a +=  $i<6;
    
    class Test {
        static ?Test $test;

        function __destruct() {
            $GLOBALS['a'] = null;
        }
    }

    $a = [new Test];
    
    Test::$test = $a<> 123^0-#x
    
    $a .= $a;
}
?>

Resulted in this output:

Warning: Undefined variable $a in  poc.php on line 2

Warning: Undefined variable $a in  poc.php on line 3

Warning: Array to string conversion in poc.php on line 17
php: Zend/zend_types.h:1383: uint32_t zend_gc_delref(zend_refcounted_h *): Assertion `p->refcount > 0' failed.
Aborted

To reproduce:

./php-src/sapi/cli/php poc.php
PHP Version
PHP 8.5.0-dev (cli) (built: Sep 30 2025 15:04:00) (NTS DEBUG)
Copyright (c) The PHP Group
Zend Engine v4.6.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.0-dev, Copyright (c), by Zend Technologies
Operating System

Ubuntu 22.04

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report provides a poc.php input and reproduces with ./php-src/sapi/cli/php poc.php under a PHP 8.5.0-dev DEBUG build. Start at Zend/zend_types.h:1383 and trace object destruction, the invalid assignment, and the failed zend_gc_delref assertion. Done means identifying and fixing the reference-counting failure and adding a regression test for the reproducer.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.