Open YuanchengJiang opened 1 month ago
This code fragment triggers infinite call recursion, and so the segfault comes from running out of stack space. For VM re-entry, we do check the stack limit and exit the program gracefully in that case. However, here there is no VM re-entry, it all happens on the C side. There's similar situations in where you can trick some extensions that wrap C libraries to do infinite recursion by constructing your code in a certain way, and that would also result in a segfault. I think this lies in the same category conceptually. cc @arnaud-lb Do you think we should do anything here or is this a won't-fix?
I think we could add an explicit stack limit check in MultipleIterator, as it's cheap and doesn't really increase complexity (compared to e.g. adding guards). It would improve user experience slightly.
@arnaud-lb While that is true, where does this stop? Just doing MultipleIterator seems ad-hoc to me. Do we really want to add a stack check to any internal C code that can recurse?
It's definitely ad-hoc, and I don't know how many of these checks would be necessary. If we only need a few here and there it would be ok in my opinion.
A more general solution would be to detect overflows with a guard page and signals. However we cannot nicely stop recursion and recover. We have to either abort or grow the stack (eventually leading to OOM).
If we only need a few here and there it would be ok in my opinion.
Honestly, I'm not a fan of that idea, I think that will quickly become an inconsistent mess.
Description
The following code:
PHP Version
PHP 8.4.0-dev
Operating System
ubuntu 22.04