nette / tracy

😎 Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.
https://tracy.nette.org
Other
1.76k stars 218 forks source link

BlueScreen callstack output can be looped by writing a exception with recursion previous property #499

Closed janbarasek closed 3 years ago

janbarasek commented 3 years ago

Version: all

Bug Description

In Tracy, there is a way to use recursive exceptions to drop the entire capture process via repeatedly writing previous.

Steps To Reproduce

How to kill your application.

Use this code:

$a = new class extends \RuntimeException {
    public function setPrevious(\Throwable $e): void
    {
        $ref = new \ReflectionClass($this);
        $parent = $ref->getParentClass()->getParentClass();
        $previous = $parent->getProperty('previous');
        $previous->setAccessible(true);
        $previous->setValue($this, $e);
    }
};
$a->setPrevious($a);

// this line will kill your BlueScreen:
throw $a;

Dumped value is:

Snímek obrazovky 2021-08-03 v 20 19 32

Note the recursion on the previous property, where Tracy recognizes it correctly. This logic must also be in the callstack statement.

Expected Behavior

Stop callstack dumping in case of recursion, or at least limit the depth.

Thanks.

mabar commented 3 years ago

Dump looks correct. Instance refers to itself and dump stopped due to recursion. It even shows the same object id #369 to inform you it's the same instance.

I can't reproduce infinite loop killing application with following script - with Tracy enabled. But the same code in Nette presenter without Tracy enabled creates infinite loop. Problem is somewhere else, probably better use xdebug step debugging to find where the issue actually is.

<?php declare(strict_types = 1);

require __DIR__ . '/../vendor/autoload.php';

\Tracy\Debugger::enable(true);

$a = new class extends \RuntimeException {
    public function setPrevious(\Throwable $e): void
    {
        $ref = new \ReflectionClass($this);
        $parent = $ref->getParentClass()->getParentClass();
        $previous = $parent->getProperty('previous');
        $previous->setAccessible(true);
        $previous->setValue($this, $e);
    }
};
$a->setPrevious($a);
throw $a;