Skip to content

Commit

Permalink
Added early return case when result is 0 (#16697)
Browse files Browse the repository at this point in the history
fixes #16265
closes #16697
  • Loading branch information
SakiTakamachi committed Nov 4, 2024
1 parent cc39bc2 commit 2fe7719
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
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.0RC4

- BcMath:
. Fixed bug GH-16265 (Added early return case when result is 0)
(Saki Takamachi).

- Core:
. Fixed bug GH-16574 (Incorrect error "undefined method" messages).
(nielsdos)
Expand Down
5 changes: 5 additions & 0 deletions ext/bcmath/libbcmath/src/div.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@ bool bc_divide(bc_num numerator, bc_num divisor, bc_num *quot, size_t scale)
/* Length of numerator data that can be read */
size_t numerator_readable_len = numeratorend - numeratorptr + 1;

if (divisor_len > numerator_readable_len + numerator_bottom_extension) {
*quot = bc_copy_num(BCG(_zero_));
return true;
}

/* If divisor is 1 here, return the result of adjusting the decimal point position of numerator. */
if (divisor_len == 1 && *divisorptr == 1) {
if (numerator_len == 0) {
Expand Down
12 changes: 12 additions & 0 deletions ext/bcmath/tests/gh16265.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
GH-16265 Segmentation fault (index oob) in ext/bcmath/libbcmath/src/convert.c:155
--EXTENSIONS--
bcmath
--INI--
bcmath.scale=0
--FILE--
<?php
echo bcdiv('-0.01', -12.3456789000e10, 9);
?>
--EXPECT--
0.000000000

0 comments on commit 2fe7719

Please sign in to comment.