Skip to content

Commit bd6b9df

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-16890: array_sum() with GMP can loose precision (LLP64)
2 parents ba8e3e1 + cfcf5cf commit bd6b9df

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug GH-16906 (Reloading document can cause UAF in iterator).
77
(nielsdos)
88

9+
- GMP:
10+
. Fixed bug GH-16890 (array_sum() with GMP can loose precision (LLP64)).
11+
(cmb)
12+
913
- Opcache:
1014
. Fixed bug GH-16851 (JIT_G(enabled) not set correctly on other threads).
1115
(dktapps)

ext/gmp/gmp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#include "ext/random/php_random.h"
3333
#include "ext/random/php_random_csprng.h"
3434

35+
#ifndef mpz_fits_si_p
36+
# define mpz_fits_si_p mpz_fits_slong_p
37+
#endif
38+
3539
#define GMP_ROUND_ZERO 0
3640
#define GMP_ROUND_PLUSINF 1
3741
#define GMP_ROUND_MINUSINF 2
@@ -293,7 +297,7 @@ static zend_result gmp_cast_object(zend_object *readobj, zval *writeobj, int typ
293297
return SUCCESS;
294298
case _IS_NUMBER:
295299
gmpnum = GET_GMP_OBJECT_FROM_OBJ(readobj)->num;
296-
if (mpz_fits_slong_p(gmpnum)) {
300+
if (mpz_fits_si_p(gmpnum)) {
297301
ZVAL_LONG(writeobj, mpz_get_si(gmpnum));
298302
} else {
299303
ZVAL_DOUBLE(writeobj, mpz_get_d(gmpnum));

ext/gmp/tests/gh16890.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
GH-16890 (array_sum() with GMP can loose precision (LLP64))
3+
--EXTENSIONS--
4+
gmp
5+
--FILE--
6+
<?php
7+
$large_int_string = (string) (PHP_INT_MAX - 1);
8+
var_dump(array_sum([new GMP($large_int_string), 1]) === PHP_INT_MAX);
9+
?>
10+
--EXPECT--
11+
bool(true)

0 commit comments

Comments
 (0)