Skip to content

Commit f61b1fc

Browse files
committed
Fix block_pass JMP[N]Z optimization
In the following optimization: JMPZ(X,L1) JMP(L2) L1: -> JMPNZ(X,L2) NOP L1 must not be followed by another block, so that it may safely be followed by the block containing the JMPNZ. get_next_block() is used to verify L1 is the direct follower. This function also skips empty blocks, including live, empty target blocks, which will then implicitly follow the new follow block. This will result in L1 being followed by two separate blocks, which is not possible. Resolve this by get_next_block() stopping at target blocks. Fixes OSS-Fuzz #472563272 Closes GH-20850
1 parent 6f6c9e3 commit f61b1fc

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PHP NEWS
66
. Fixed bug GH-20837 (NULL dereference when calling ob_start() in shutdown
77
function triggered by bailout in php_output_lock_error()). (timwolla)
88
. Fix OSS-Fuzz #471533782 (Infinite loop in GC destructor fiber). (ilutov)
9+
. Fix OSS-Fuzz #472563272 (Borked block_pass JMP[N]Z optimization). (ilutov)
910

1011
- MbString:
1112
. Fixed bug GH-20833 (mb_str_pad() divide by zero if padding string is

Zend/Optimizer/block_pass.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ static zend_always_inline zend_basic_block *get_next_block(const zend_cfg *cfg,
11521152
}
11531153
next_block++;
11541154
}
1155-
while (next_block->len == 0 && !(next_block->flags & ZEND_BB_PROTECTED)) {
1155+
while (next_block->len == 0 && !(next_block->flags & (ZEND_BB_TARGET|ZEND_BB_PROTECTED))) {
11561156
next_block = cfg->blocks + next_block->successors[0];
11571157
}
11581158
return next_block;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
OSS-Fuzz #472563272: Borked block_pass JMP[N]Z optimization
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
--FILE--
9+
<?php
10+
false || (true ? true : false) || (false ? true : false) || true;
11+
?>
12+
===DONE===
13+
--EXPECT--
14+
===DONE===

0 commit comments

Comments
 (0)