Skip to content
Open
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
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.4.25

- BCMath:
. Fixed out-of-bounds read in bc_is_zero_for_scale() when scale exceeds
n_scale. (iliaal)

- Date:
. Fixed leak on double DatePeriod::__construct() call. (ilutov)

Expand Down
4 changes: 4 additions & 0 deletions ext/bcmath/libbcmath/src/zero.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ bool bc_is_zero_for_scale(bc_num num, size_t scale)
return true;
}

if (scale > num->n_scale) {
scale = num->n_scale;
}

/* Initialize */
count = num->n_len + scale;
nptr = num->n_value;
Expand Down
12 changes: 12 additions & 0 deletions ext/bcmath/tests/bc_is_zero_for_scale_clamp.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
bc_is_zero_for_scale clamps scale to n_scale (Number::compare opposite signs)
--EXTENSIONS--
bcmath
--FILE--
<?php
$shortZero = (new BcMath\Number('1.0'))->sub('1.0');
$longNegative = new BcMath\Number('-0.' . str_repeat('0', 64) . '1');
var_dump($shortZero->compare($longNegative, 64));
?>
--EXPECT--
int(0)
Loading