-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Bug #76844 PHP crashes on big file with array inside #11240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Here's a PoC patch (on top of current PHP-8.1 branch) that solves the issue by modifying Tarjan's SCC implementation to an iterative approach. The transformation is quite mechanical so perhaps there's room for improvement. I ran out of time for today so I didn't have the chance to check the correctness, or how well it performs vs the old recursive implementation. An extra pair of eyes is welcome as always :) ** old patch **
```diff
diff --git a/Zend/Optimizer/zend_inference.c b/Zend/Optimizer/zend_inference.c
index 91a142a9f8..7e2eb433c2 100644
--- a/Zend/Optimizer/zend_inference.c
+++ b/Zend/Optimizer/zend_inference.c
@@ -74,18 +74,6 @@
} \
} while (0)
-#define CHECK_SCC_VAR(var2) \
#define CHECK_SCC_ENTRY(var2) -static void zend_ssa_check_scc_var(const zend_op_array *op_array, zend_ssa *ssa, int var, int *index, int *dfs, int *root, zend_worklist_stack stack) / {{{ */
+#define CHECK_SCC_VAR(var2) \
#ifdef SYM_RANGE
#endif
ZEND_API int zend_ssa_find_sccs(const zend_op_array *op_array, zend_ssa ssa) / {{{ */
|
The crash happens because there's a stack overflow in the recursive SCC algorithm. Fix this by transforming it into an iterative implementation of the same algorithm. We manually keep the recursion stack now. I tested the correctness by running the CI test suite using both the old implementation and the new implementation and letting the test fail if the SCC values differ. The tests passed without failure. For the test case of OP, I benchmarked the performance: With this patch Time (mean ± σ): 645.9 ms ± 7.4 ms [User: 603.7 ms, System: 40.7 ms] Range (min … max): 634.0 ms … 659.3 ms 10 runs Without this patch Time (mean ± σ): 755.3 ms ± 18.1 ms [User: 698.8 ms, System: 55.2 ms] Range (min … max): 737.6 ms … 784.4 ms 10 runs We can see an improvement in performance as well because the function call overhead and control transfer overhead is eliminated now.
Wanted to come back and say thanks to everyone. It's good to put one in the win column sometimes. (whereas my Apple bug reports seem to be printed out directly into a shredder) |
Description
https://bugs.php.net/bug.php?id=76844
I typed up a really nice thing and then the browser crashed so I'm not doing that again 😭
Run code, then run the code it makes.
it does it on PHP 8.2.5 on CentOS 7 and PHP 8.2.6 on Mac Venture whatever (after you fix the install). This bug was never fixed.
PHP Version
8.2.5
Operating System
No response
The text was updated successfully, but these errors were encountered: