Skip to content

Commit 65120cf

Browse files
committed
Fixed bug #79412 (Opcache chokes and uses 100% CPU on specific script).
1 parent c0840fe commit 65120cf

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PHP NEWS
1616
- Iconv:
1717
. Fixed bug #79200 (Some iconv functions cut Windows-1258). (cmb)
1818

19+
- OPcache:
20+
. Fixed bug #79412 (Opcache chokes and uses 100% CPU on specific script).
21+
(Dmitry)
22+
1923
- SimpleXML:
2024
. Fixed bug #61597 (SXE properties may lack attributes and content). (cmb)
2125

ext/opcache/Optimizer/zend_inference.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,12 +1807,25 @@ static int zend_infer_ranges(const zend_op_array *op_array, zend_ssa *ssa) /* {{
18071807
}
18081808
} WHILE_WORKLIST_END();
18091809

1810-
/* Add all SCC entry variables into worklist for narrowing */
1810+
/* initialize missing ranges */
18111811
for (j = scc_var[scc]; j >= 0; j = next_scc_var[j]) {
18121812
if (!ssa->var_info[j].has_range) {
18131813
zend_inference_init_range(op_array, ssa, j, 1, ZEND_LONG_MIN, ZEND_LONG_MAX, 1);
1814-
} else if (ssa->vars[j].definition_phi &&
1815-
ssa->vars[j].definition_phi->pi < 0) {
1814+
FOR_EACH_VAR_USAGE(j, ADD_SCC_VAR);
1815+
}
1816+
}
1817+
1818+
/* widening (second round) */
1819+
WHILE_WORKLIST(worklist, worklist_len, j) {
1820+
if (zend_ssa_range_widening(op_array, ssa, j, scc)) {
1821+
FOR_EACH_VAR_USAGE(j, ADD_SCC_VAR);
1822+
}
1823+
} WHILE_WORKLIST_END();
1824+
1825+
/* Add all SCC entry variables into worklist for narrowing */
1826+
for (j = scc_var[scc]; j >= 0; j = next_scc_var[j]) {
1827+
if (ssa->vars[j].definition_phi
1828+
&& ssa->vars[j].definition_phi->pi < 0) {
18161829
/* narrowing Phi functions first */
18171830
zend_ssa_range_narrowing(op_array, ssa, j, scc);
18181831
}

ext/opcache/tests/bug79412.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #79412 (Opcache chokes and uses 100% CPU on specific script)
3+
--INI--
4+
opcache.enable=1
5+
opcache.optimization_level=-1
6+
--SKIPIF--
7+
<?php require_once('skipif.inc'); ?>
8+
--FILE--
9+
<?php
10+
$limitPerRun = 10;
11+
foreach ($foo as $bar) {
12+
$count = 0;
13+
foreach ($runs as $run) {
14+
++$count;
15+
if ($count >= $limitPerRun) {
16+
break;
17+
}
18+
}
19+
foo($limitPerRun);
20+
}
21+
?>
22+
--EXPECTF--
23+
Notice: Undefined variable: foo in %s on line %d
24+
25+
Warning: Invalid argument supplied for foreach() in %s on line %d

0 commit comments

Comments
 (0)