[php-src] Issue #18819: php-gmp is using a version of libgmp that terminates the process on several operations
| From: | sha0coder | Date: | Tue, 10 Jun 2025 08:49:31 +0000 |
| Subject: | [php-src] Issue #18819: php-gmp is using a version of libgmp that terminates the process on several operations | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-250229@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/18819
Author: sha0coder
### Description
The following code:
```php
~ ❯❯❯ php8.4 -a
✘ 134
Interactive shell
php > $trigger=0xfffffffff; $a = gmp_init("241"); $b = 137; $a = gmp_mul($a,
gmp_pow(2, $b)); $a = gmp_strval( gmp_pow( $b, $trigger)); echo $a . "\n";
```
Resulted in this output:
```
gmp: overflow in mpz type
fish: Job 1, 'php8.4 -a' terminated by signal SIGABRT (Abort)
```
php-gmp is using a version of the library libgmp that __gmpz_n_pow_ui triggers abort() on specific
cases.
They uses MUL instruction and check if rdx>0 then abort process.


if $trigger is 0xffffffff --> consume resources infinitely (prolly because my php.ini's
memory_limit = -1)
if $trigger is 0xfffffffff -> abort() call ends the php process.
regards.
### PHP Version
```plain
PHP 8.4.7 (cli) (built: May 9 2025 06:54:08) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.7, Copyright (c) Zend Technologies
with Zend OPcache v8.4.7, Copyright (c), by Zend Technologies
```
### Operating System
pop-os