]> granicus.if.org Git - php/commitdiff
Fixed bug #79412 (Opcache chokes and uses 100% CPU on specific script).
authorDmitry Stogov <dmitry@zend.com>
Wed, 25 Mar 2020 14:31:06 +0000 (17:31 +0300)
committerDmitry Stogov <dmitry@zend.com>
Wed, 25 Mar 2020 14:31:06 +0000 (17:31 +0300)
NEWS
ext/opcache/Optimizer/zend_inference.c
ext/opcache/tests/bug79412.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index ddcebd14fc0bb507fe3222e2c9d1170c652a3084..edd69bb27a95ee633743d1be95bc33a2eaad788a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,10 @@ PHP                                                                        NEWS
 - Iconv:
   . Fixed bug #79200 (Some iconv functions cut Windows-1258). (cmb)
 
+- OPcache:
+  . Fixed bug #79412 (Opcache chokes and uses 100% CPU on specific script).
+    (Dmitry)
+
 - SimpleXML:
   . Fixed bug #61597 (SXE properties may lack attributes and content). (cmb)
 
index a60ecef888d7a940bb6429b79f3142d47a6196a8..2579d3ff9683d9c35d0ce3e3ca61f411859708cc 100644 (file)
@@ -1807,12 +1807,25 @@ static int zend_infer_ranges(const zend_op_array *op_array, zend_ssa *ssa) /* {{
                                }
                        } WHILE_WORKLIST_END();
 
-                       /* Add all SCC entry variables into worklist for narrowing */
+                       /* initialize missing ranges */
                        for (j = scc_var[scc]; j >= 0; j = next_scc_var[j]) {
                                if (!ssa->var_info[j].has_range) {
                                        zend_inference_init_range(op_array, ssa, j, 1, ZEND_LONG_MIN, ZEND_LONG_MAX, 1);
-                               } else if (ssa->vars[j].definition_phi &&
-                                          ssa->vars[j].definition_phi->pi < 0) {
+                                       FOR_EACH_VAR_USAGE(j, ADD_SCC_VAR);
+                               }
+                       }
+
+                       /* widening (second round) */
+                       WHILE_WORKLIST(worklist, worklist_len, j) {
+                               if (zend_ssa_range_widening(op_array, ssa, j, scc)) {
+                                       FOR_EACH_VAR_USAGE(j, ADD_SCC_VAR);
+                               }
+                       } WHILE_WORKLIST_END();
+
+                       /* Add all SCC entry variables into worklist for narrowing */
+                       for (j = scc_var[scc]; j >= 0; j = next_scc_var[j]) {
+                               if (ssa->vars[j].definition_phi
+                                && ssa->vars[j].definition_phi->pi < 0) {
                                        /* narrowing Phi functions first */
                                        zend_ssa_range_narrowing(op_array, ssa, j, scc);
                                }
diff --git a/ext/opcache/tests/bug79412.phpt b/ext/opcache/tests/bug79412.phpt
new file mode 100644 (file)
index 0000000..20fb0a5
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Bug #79412 (Opcache chokes and uses 100% CPU on specific script)
+--INI--
+opcache.enable=1
+opcache.optimization_level=-1
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+$limitPerRun = 10;
+foreach ($foo as $bar) {
+    $count = 0;
+    foreach ($runs as $run) {
+        ++$count;
+        if ($count >= $limitPerRun) {
+            break;
+        }
+    }
+    foo($limitPerRun);
+}
+?>
+--EXPECTF--
+Notice: Undefined variable: foo in %s on line %d
+
+Warning: Invalid argument supplied for foreach() in %s on line %d