Skip to content

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

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

Activity

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

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions