[php-src] Issue #16041: Segmentation fault (stack overflow in phpdbg) in main/spprintf.c
| From: | YuanchengJiang | Date: | Wed, 25 Sep 2024 05:01:44 +0000 |
| Subject: | [php-src] Issue #16041: Segmentation fault (stack overflow in phpdbg) in main/spprintf.c | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247894@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/16041
Author: YuanchengJiang
### Description
The following code:
```php
<?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