Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Zend/tests/oss_fuzz_447521098.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
OSS-Fuzz #447521098: Fatal error during sccp shift eval
--FILE--
<?php
function test() {
$x = 0;
$y = -1;
$x >> $y;
}
?>
===DONE===
--EXPECT--
===DONE===
8 changes: 6 additions & 2 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -9998,7 +9998,9 @@ ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, co
/* Operation which cast float/float-strings to integers might produce incompatible float to int errors */
if (opcode == ZEND_SL || opcode == ZEND_SR || opcode == ZEND_BW_OR
|| opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR) {
return !zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2);
if (!zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2)) {
return 1;
}
Comment on lines 9999 to +10003
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other thing you could do, is move the:

	if ((opcode == ZEND_SL || opcode == ZEND_SR) && zval_get_long(op2) < 0) {
		/* Shift by negative number throws an error. */
		return 1;
	}

code check above this one or move this back to be last check as it was previously. This shouldn't be a problem now that ZEND_MOD is dealt separately.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's great to mix early returns for positive and negative results (or conditional results), as checks become order-dependent. I'll keep this simple change for now, but if you feel strongly you can still adjust on master.

}

if (opcode == ZEND_DIV && zval_get_double(op2) == 0.0) {
Expand All @@ -10009,7 +10011,9 @@ ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, co
/* Mod is an operation that will cast float/float-strings to integers which might
produce float to int incompatible errors, and also cannot be divided by 0 */
if (opcode == ZEND_MOD) {
return !zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2) || zval_get_long(op2) == 0;
if (!zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2) || zval_get_long(op2) == 0) {
return 1;
}
}

if ((opcode == ZEND_POW) && zval_get_double(op1) == 0 && zval_get_double(op2) < 0) {
Expand Down