Skip to content

Commit 9874dcc

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: JIT: Fix SIGFPE on LONG_MIN % -1 with a constant divisor
2 parents d4e0d68 + fe6a0ef commit 9874dcc

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎NEWS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ PHP NEWS
6262
property). (Lazizbek Ergashev)
6363
. Fixed bug GH-24185 (Windows ZTS: random access violations with OPcache JIT
6464
in multi-process setups). (Arnaud, ndossche)
65+
. Fix SIGFPE on LONG_MIN % -1 with a constant divisor. (waroad)
6566

6667
- PDO:
6768
. Fixed a duplicate warning when ATTR_STATEMENT_CLASS is rejected on a

‎ext/opcache/jit/zend_jit_ir.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5805,6 +5805,9 @@ static int zend_jit_long_math_helper(zend_jit_ctx *jit,
58055805
if (Z_MODE(res_addr) == IS_REG) {
58065806
ref = ir_CONST_LONG(0); // dead code
58075807
}
5808+
} else if (op2_lval == -1) {
5809+
/* Prevent overflow error/crash if op1 == LONG_MIN */
5810+
ref = ir_CONST_LONG(0);
58085811
} else if (zend_long_is_power_of_two(op2_lval) && op1_range && op1_range->min >= 0) {
58095812
ref = ir_AND_L(jit_Z_LVAL(jit, op1_addr), ir_CONST_LONG(op2_lval - 1));
58105813
} else {

‎ext/opcache/tests/jit/mod_002.phpt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var_dump(modNeg33(125));
3232
var_dump(modNeg33(-125));
3333
try {
3434
var_dump(modNeg1(125));
35+
var_dump(modNeg1(PHP_INT_MIN));
3536
} catch (Throwable $e) {
3637
echo "Exception " . $e->getMessage() . "\n";
3738
}
@@ -49,4 +50,5 @@ int(-29)
4950
int(26)
5051
int(-26)
5152
int(0)
53+
int(0)
5254
Exception (DivisionByZeroError): Modulo by zero

0 commit comments

Comments
 (0)