Skip to content

Commit 2fe7719

Browse files
committed
Added early return case when result is 0 (#16697)
fixes #16265 closes #16697
1 parent cc39bc2 commit 2fe7719

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

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.4.0RC4
44

5+
- BcMath:
6+
. Fixed bug GH-16265 (Added early return case when result is 0)
7+
(Saki Takamachi).
8+
59
- Core:
610
. Fixed bug GH-16574 (Incorrect error "undefined method" messages).
711
(nielsdos)

ext/bcmath/libbcmath/src/div.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,11 @@ bool bc_divide(bc_num numerator, bc_num divisor, bc_num *quot, size_t scale)
444444
/* Length of numerator data that can be read */
445445
size_t numerator_readable_len = numeratorend - numeratorptr + 1;
446446

447+
if (divisor_len > numerator_readable_len + numerator_bottom_extension) {
448+
*quot = bc_copy_num(BCG(_zero_));
449+
return true;
450+
}
451+
447452
/* If divisor is 1 here, return the result of adjusting the decimal point position of numerator. */
448453
if (divisor_len == 1 && *divisorptr == 1) {
449454
if (numerator_len == 0) {

ext/bcmath/tests/gh16265.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-16265 Segmentation fault (index oob) in ext/bcmath/libbcmath/src/convert.c:155
3+
--EXTENSIONS--
4+
bcmath
5+
--INI--
6+
bcmath.scale=0
7+
--FILE--
8+
<?php
9+
echo bcdiv('-0.01', -12.3456789000e10, 9);
10+
?>
11+
--EXPECT--
12+
0.000000000

0 commit comments

Comments
 (0)