php / php-src

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

Fix GH-16878: gmp_fact overflow on memory allocation attempt. #16880

Open devnexen opened 5 days ago

Girgias commented 3 days ago

On my machine (64bit) the largest factorial I can attempt to compute is 471778098879 the boundary where it fails is 471778098880 = 64 * 7371532795. So we could compare against this.

Girgias commented 3 days ago

Well that still OOMs on 48GB of RAM so, that's not the upper boundary then.

cmb69 commented 1 day ago

Roughly 4294967296! might fit into 16GB. 16GB == 2^37 bits is still quite excessive. Especially if we revert/do not introduce these bounds check for stable versions, in my opinion, we could go with far less, maybe even only 2^24 bits (in which case !2790877 would be the maximum).

Girgias commented 18 hours ago

Yeah, I was just trying to see what was theoretically possible. :)

I am happy to restrict it to !2790877 :)