You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug #76844 PHP crashes on big file with array inside #11240
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 :)
if (ssa->vars[var2].scc < 0 && dfs[root[var]] >= dfs[root[var2]]) { \
root[var] = root[var2]; \
} \
} \
} while (0)
#define CHECK_SCC_ENTRY(var2)
do {
if (ssa->vars[var2].scc != ssa->vars[var].scc) {
@@ -172,43 +160,78 @@ static inline bool sub_will_overflow(zend_long a, zend_long b) {
}
#endif
-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) / {{{ */
+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)
{
-#ifdef SYM_RANGE
zend_ssa_phi *p;
-#endif
zend_worklist_stack node_stack;
ALLOCA_FLAG(node_stack_use_heap);
/* Format: first we have the from node, then we have to to node.
If the from node is negative, then we haven't gone back yet. */
EDIT: I benchmarked (by putting the stack limit to unlimited).
**NEW**
Time (mean ± σ): 517.3 ms ± 3.5 ms [User: 486.4 ms, System: 28.7 ms]
Range (min … max): 513.0 ms … 523.5 ms 10 runs
**OLD**
Time (mean ± σ): 530.6 ms ± 4.8 ms [User: 492.9 ms, System: 35.5 ms]
Range (min … max): 524.9 ms … 539.9 ms 10 runs
So no performance degradation by switching to an iterative approach.
</details>
EDIT: I'm currently working on a new patch for this based on the above PoC.
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)
Activity
ndossche commentedon May 14, 2023
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 **
Details
```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)
do {
if (ssa->vars[var2].scc != ssa->vars[var].scc) {
@@ -172,43 +160,78 @@ static inline bool sub_will_overflow(zend_long a, zend_long b) {
}
#endif
-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) / {{{ */
+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)
{
-#ifdef SYM_RANGE
-#endif
+#define CHECK_SCC_VAR(var2) \
do { \
} while (0)
zend_worklist_stack_push(&node_stack, -var - 1);
zend_worklist_stack_push(&node_stack, var);
dfs[var] = *index;
(*index)++;
root[var] = var;
while (node_stack.len > 0) {
#ifdef SYM_RANGE
#endif
}
-/* }}} */
ZEND_API int zend_ssa_find_sccs(const zend_op_array *op_array, zend_ssa ssa) / {{{ */
{
Fix phpGH-11240: PHP crashes on big file with array inside
MikeRich88 commentedon Oct 27, 2023
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)