php / php-src

The PHP Interpreter
https://www.php.net
Other
38.3k stars 7.76k forks source link

Overflow in pow() #16502

Open YuanchengJiang opened 1 month ago

YuanchengJiang commented 1 month ago

Description

The following code:

<?php
$a = gmp_init(10000000000);
var_dump(pow($a, $a)); // or var_dump($a**$a);

Resulted in this output:

gmp: overflow in mpz type
Aborted (core dumped)

But I expected this output instead:

float(INF)

PHP Version

nightly

Operating System

ubuntu 22.04

cmb69 commented 1 month ago

Apparently, the library aborts, instead of signaling failure by some other means. At least mpir 3.0.0, which we use on Windows (and which is no longer maintained), aborts even on memory allocation failures. If gmplib behaves the same, it might not something we can fix.

cmb69 commented 1 month ago

I think we should call mp_set_memory_functions() to install ZendMM.

PS: see #16507.

cmb69 commented 1 month ago

Possibly partial fix for this issue on Windows: https://github.com/BrianGladman/mpir/commit/33be9007f95b85230da2330ef3ed525896370cc2