Skip to content

Commit 1d004f0

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Clamp scale in bc_is_zero_for_scale to n_scale
2 parents 148932c + 18cd150 commit 1d004f0

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.6.0beta3
44

5+
- BCMath:
6+
. Fixed out-of-bounds read in bc_is_zero_for_scale() when scale exceeds
7+
n_scale. (Ilia Alshanetsky)
8+
59
- Core:
610
. Calling is_a() or is_subclass_of() with a string as the first argument
711
when $allow_string is false is now deprecated. (Daniel Scherzer)

ext/bcmath/libbcmath/src/zero.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ bool bc_is_zero_for_scale(bc_num num, size_t scale)
4545
return true;
4646
}
4747

48+
if (scale > num->n_scale) {
49+
scale = num->n_scale;
50+
}
51+
4852
/* Initialize */
4953
count = num->n_len + scale;
5054
nptr = num->n_value;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
bc_is_zero_for_scale clamps scale to n_scale (Number::compare opposite signs)
3+
--EXTENSIONS--
4+
bcmath
5+
--FILE--
6+
<?php
7+
$shortZero = (new BcMath\Number('1.0'))->sub('1.0');
8+
$longNegative = new BcMath\Number('-0.' . str_repeat('0', 64) . '1');
9+
var_dump($shortZero->compare($longNegative, 64));
10+
?>
11+
--EXPECT--
12+
int(0)

0 commit comments

Comments
 (0)