diff --git a/ext/bcmath/libbcmath/src/raise.c b/ext/bcmath/libbcmath/src/raise.c index 5df8130c24219..959ba924e57fd 100644 --- a/ext/bcmath/libbcmath/src/raise.c +++ b/ext/bcmath/libbcmath/src/raise.c @@ -193,7 +193,12 @@ bc_raise_status bc_raise(bc_num base, long exponent, bc_num *result, size_t scal if (bc_is_zero(base)) { /* If the exponent is negative, it divides by 0 */ - return is_neg ? BC_RAISE_STATUS_DIVIDE_BY_ZERO : BC_RAISE_STATUS_OK; + if (is_neg) { + return BC_RAISE_STATUS_DIVIDE_BY_ZERO; + } + bc_free_num (result); + *result = bc_copy_num(BCG(_zero_)); + return BC_RAISE_STATUS_OK; } /* check overflow */ diff --git a/ext/bcmath/tests/gh20006.phpt b/ext/bcmath/tests/gh20006.phpt new file mode 100644 index 0000000000000..ab0db915152d3 --- /dev/null +++ b/ext/bcmath/tests/gh20006.phpt @@ -0,0 +1,16 @@ +--TEST-- +GH-20006 (Power of 0 of BcMath number causes crash) +--EXTENSIONS-- +bcmath +--FILE-- + +--EXPECTF-- +object(BcMath\Number)#%d (2) { + ["value"]=> + string(1) "0" + ["scale"]=> + int(0) +}