Skip to content

Segmentation fault (stack overflow in phpdbg) in main/spprintf.c  #16041

Closed
@YuanchengJiang

Description

@YuanchengJiang

Description

The following code:

<?php
final class StreamWrapper
{
    public $context;
}
$fusion = $context;
register_shutdown_function(function () {
    global $shutdown;
    $shutdown = true;
});
class Cycle {
    public $self;
    public function __construct() {
        $this->self = $this;
    }
}
class Canary {
    public $self;
    public function __construct() {
        $this->self = $fusion;
    }
    public function __destruct() {
        global $shutdown;
        if (!$shutdown) {
            work();
        }
    }
}
function work() {
    global $objs, $defaultThreshold;
    new Canary();
    // Create some collectable garbage so the next run will not adjust
    // threshold
    for ($i = 0; $i < 100; $i++) {
        new Cycle();
    }
    // Add potential garbage to buffer
    foreach (array_slice($objs, 0, $defaultThreshold) as $obj) {
        $o = $obj;
    }
}
work();
?>

To reproduce:

phpdbg test.php
> r

PHP Version

PHP 8.4.0-dev

Operating System

ubuntu 22.04

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