emgiezet / errbit-php

PHP Errbit/AirBrake Client - Only One Working and Tested
45 stars 12 forks source link

add recursion protection for Errbit\Exception\Notice->xmlVarsFor() #14

Closed Tyrael closed 10 years ago

Tyrael commented 10 years ago

variables (mostly objects, as they are passed by ~reference by default) can have references to themselves or each other, which will cause an infinite loop when you are trying to iterate over $array in the xmlVarsFor() method. you could store and check the spl_object_hash() result for each object when iterating through the $array, and skip the building(or assign the value "RECURSION" to any other occurance to better match the print_r() behavior) of those objects which were traversed already.

emgiezet commented 10 years ago

I'm using this a lot with Symfony2 (2.1, 2.2, 2.3, 2.4) and recursion never happened to me.

In most cases I'm using

xdebug.max_nesting_level = 200

I guess that situation will appear you passing some hydrated Doctrine object to the session.

I'm not sure but here the serialization can be helpful. Need some more info from you.

Regards, Max

Tyrael commented 10 years ago

unfortunately xdebug has some measurable performance impact and can also cause differences in the application behavior (http://bugs.xdebug.org/view.php?id=587 has bitten me in the past, before it got fixed). even if you consider this solution, that still means that some errors/notices can abort the execution of your script, and if errbit is your only error handler, you won't even notice the problem until users start complaining about it.

you don't really need a large object collection for this to happen (albeit it is more common with large objects referencing a bunch of other objects): simple example: http://3v4l.org/pqYpr

a simple snippet showing the infinite recursion with such data: http://3v4l.org/rSg42

emgiezet commented 10 years ago

So what do you think @Tyrael right now?

Tyrael commented 10 years ago

it seems fine, and I really like that you also added a test for it.

emgiezet commented 10 years ago

Its not me, but my friend @filipc.

Thanks Again Filip!

Tyrael commented 10 years ago

yeah, thanks both of you! do you have any ETA for the next tag?

emgiezet commented 10 years ago

How about now? :)

Tyrael commented 10 years ago

\o/

emgiezet commented 10 years ago

ok packagist is updated.