Skip to content

Commit 2a4d294

Browse files
committed
Handle PHP_INT_MIN properly
1 parent c041da5 commit 2a4d294

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Zend/tests/zend_ini/zend_ini_parse_quantity_overflow.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ $tests = [
3030
'No overflow 002' => '1',
3131
'No overflow 003' => '100',
3232
'No overflow 004' => strval(PHP_INT_MAX),
33-
'No overflow 005' => strval(-PHP_INT_MAX),
33+
'No overflow 005' => strval(PHP_INT_MIN),
3434
'No overflow 006' => '2K',
3535
'No overflow 007' => '-2K',
3636
'Subject overflow 001' => increment(strval(PHP_INT_MAX)),
37-
'Subject overflow 002' => decrement(strval(-PHP_INT_MAX)),
37+
'Subject overflow 002' => decrement(strval(PHP_INT_MIN)),
3838
'Multiplier overflow 001' => strval(PHP_INT_MAX).'K',
39-
'Multiplier overflow 002' => strval(-PHP_INT_MAX).'K',
39+
'Multiplier overflow 002' => strval(PHP_INT_MIN).'K',
4040
];
4141

4242
foreach ($tests as $name => $value) {

Zend/zend_ini.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,10 @@ static zend_ulong zend_ini_parse_quantity_internal(zend_string *value, zend_ini_
642642
}
643643
}
644644
} else if (signed_result == ZEND_INI_PARSE_QUANTITY_SIGNED) {
645-
if ((zend_long) retval < 0) {
645+
/* Handle PHP_INT_MIN case */
646+
if (is_negative && retval == ((zend_ulong)ZEND_LONG_MAX +1)) {
647+
retval = 0u - retval;
648+
} else if ((zend_long) retval < 0) {
646649
overflow = true;
647650
} else if (is_negative) {
648651
retval = 0u - retval;

0 commit comments

Comments
 (0)