Skip to content

Commit d87c8be

Browse files
committed
Fixed GH-16978: Avoid unnecessary padding with leading zeros
Fixed an issue where leading zeros were padded beyond the allocated memory.
1 parent 8d25978 commit d87c8be

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

ext/bcmath/libbcmath/src/div.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ bool bc_divide(bc_num numerator, bc_num divisor, bc_num *quot, size_t scale)
436436
numerator_bottom_extension = 0;
437437
numeratorend -= scale_diff > numerator_top_extension ? scale_diff - numerator_top_extension : 0;
438438
}
439+
numerator_top_extension = MIN(numerator_top_extension, scale);
439440
} else {
440441
numerator_bottom_extension += scale - numerator_scale;
441442
}

ext/bcmath/tests/gh16978.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+
--FILE--
6+
<?php
7+
echo bcpow('10', '-112', 10) . "\n";
8+
echo bcdiv('1', '10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 1);
9+
?>
10+
--EXPECT--
11+
0.0000000000
12+
0.0

0 commit comments

Comments
 (0)