Skip to content

Commit 06bc59f

Browse files
committed
revert php commit which broke some use-cases of gmp (overzealous check for
out-of-bounds values); php/php-src#16870
1 parent 7c60128 commit 06bc59f

File tree

6 files changed

+108
-10
lines changed

6 files changed

+108
-10
lines changed

lang/php/8.2/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
PHP_VERSION= 8.2.26
2-
PHP_PKGSPEC= >=8.2,<8.3
2+
AUTOCONF_VERSION= 2.69
33

4-
# keep above 7.6-stable; @pkgpath markers, WANTLIB-gd
4+
# keep all subpackages above 7.6-stable; @pkgpath markers, WANTLIB-gd
55
REVISION= 0
6+
REVISION-gmp= 1
67

78
DEFAULT_PHP= Yes
8-
9+
PHP_PKGSPEC= >=8.2,<8.3
910
PHP_EXTENSIONS += -imap -pspell
10-
AUTOCONF_VERSION= 2.69
1111

1212
.include <bsd.port.mk>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
https://github.com/php/php-src/issues/16870
2+
3+
Index: ext/gmp/gmp.c
4+
--- ext/gmp/gmp.c.orig
5+
+++ ext/gmp/gmp.c
6+
@@ -1350,26 +1350,13 @@ ZEND_FUNCTION(gmp_pow)
7+
RETURN_THROWS();
8+
}
9+
10+
- double powmax = log((double)ZEND_LONG_MAX);
11+
-
12+
if (Z_TYPE_P(base_arg) == IS_LONG && Z_LVAL_P(base_arg) >= 0) {
13+
INIT_GMP_RETVAL(gmpnum_result);
14+
- if ((log(Z_LVAL_P(base_arg)) * exp) > powmax) {
15+
- zend_value_error("base and exponent overflow");
16+
- RETURN_THROWS();
17+
- }
18+
mpz_ui_pow_ui(gmpnum_result, Z_LVAL_P(base_arg), exp);
19+
} else {
20+
mpz_ptr gmpnum_base;
21+
- zend_ulong gmpnum;
22+
FETCH_GMP_ZVAL(gmpnum_base, base_arg, temp_base, 1);
23+
INIT_GMP_RETVAL(gmpnum_result);
24+
- gmpnum = mpz_get_ui(gmpnum_base);
25+
- if ((log(gmpnum) * exp) > powmax) {
26+
- FREE_GMP_TEMP(temp_base);
27+
- zend_value_error("base and exponent overflow");
28+
- RETURN_THROWS();
29+
- }
30+
mpz_pow_ui(gmpnum_result, gmpnum_base, exp);
31+
FREE_GMP_TEMP(temp_base);
32+
}

lang/php/8.3/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
PHP_VERSION= 8.3.14
2-
PHP_PKGSPEC= >=8.3,<8.4
2+
AUTOCONF_VERSION= 2.71
33

4-
# keep above 7.6-stable; WANTLIB-gd
4+
# keep -gd above 7.6-stable; WANTLIB
55
REVISION-gd= 0
6+
REVISION-gmp= 0
67

8+
PHP_PKGSPEC= >=8.3,<8.4
79
PHP_EXTENSIONS += -imap -pspell
8-
AUTOCONF_VERSION= 2.71
910

1011
.include <bsd.port.mk>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
https://github.com/php/php-src/issues/16870
2+
3+
Index: ext/gmp/gmp.c
4+
--- ext/gmp/gmp.c.orig
5+
+++ ext/gmp/gmp.c
6+
@@ -1350,26 +1350,13 @@ ZEND_FUNCTION(gmp_pow)
7+
RETURN_THROWS();
8+
}
9+
10+
- double powmax = log((double)ZEND_LONG_MAX);
11+
-
12+
if (Z_TYPE_P(base_arg) == IS_LONG && Z_LVAL_P(base_arg) >= 0) {
13+
INIT_GMP_RETVAL(gmpnum_result);
14+
- if ((log(Z_LVAL_P(base_arg)) * exp) > powmax) {
15+
- zend_value_error("base and exponent overflow");
16+
- RETURN_THROWS();
17+
- }
18+
mpz_ui_pow_ui(gmpnum_result, Z_LVAL_P(base_arg), exp);
19+
} else {
20+
mpz_ptr gmpnum_base;
21+
- zend_ulong gmpnum;
22+
FETCH_GMP_ZVAL(gmpnum_base, base_arg, temp_base, 1);
23+
INIT_GMP_RETVAL(gmpnum_result);
24+
- gmpnum = mpz_get_ui(gmpnum_base);
25+
- if ((log(gmpnum) * exp) > powmax) {
26+
- FREE_GMP_TEMP(temp_base);
27+
- zend_value_error("base and exponent overflow");
28+
- RETURN_THROWS();
29+
- }
30+
mpz_pow_ui(gmpnum_result, gmpnum_base, exp);
31+
FREE_GMP_TEMP(temp_base);
32+
}

lang/php/8.4/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
PHP_VERSION= 8.4.1
2-
PHP_PKGSPEC= >=8.4,<8.5
2+
AUTOCONF_VERSION= 2.72
3+
4+
REVISION-gmp= 0
35

46
# no PORTROACH marker for the highest branch, to allow finding new branches
57
PORTROACH=
6-
7-
AUTOCONF_VERSION= 2.72
8+
PHP_PKGSPEC= >=8.4,<8.5
89

910
WANTLIB-pdo_odbc += iodbcinst
1011

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
https://github.com/php/php-src/issues/16870
2+
3+
Index: ext/gmp/gmp.c
4+
--- ext/gmp/gmp.c.orig
5+
+++ ext/gmp/gmp.c
6+
@@ -1360,26 +1360,13 @@ ZEND_FUNCTION(gmp_pow)
7+
RETURN_THROWS();
8+
}
9+
10+
- double powmax = log((double)ZEND_LONG_MAX);
11+
-
12+
if (Z_TYPE_P(base_arg) == IS_LONG && Z_LVAL_P(base_arg) >= 0) {
13+
INIT_GMP_RETVAL(gmpnum_result);
14+
- if ((log(Z_LVAL_P(base_arg)) * exp) > powmax) {
15+
- zend_value_error("base and exponent overflow");
16+
- RETURN_THROWS();
17+
- }
18+
mpz_ui_pow_ui(gmpnum_result, Z_LVAL_P(base_arg), exp);
19+
} else {
20+
mpz_ptr gmpnum_base;
21+
- zend_ulong gmpnum;
22+
FETCH_GMP_ZVAL(gmpnum_base, base_arg, temp_base, 1);
23+
INIT_GMP_RETVAL(gmpnum_result);
24+
- gmpnum = mpz_get_ui(gmpnum_base);
25+
- if ((log(gmpnum) * exp) > powmax) {
26+
- FREE_GMP_TEMP(temp_base);
27+
- zend_value_error("base and exponent overflow");
28+
- RETURN_THROWS();
29+
- }
30+
mpz_pow_ui(gmpnum_result, gmpnum_base, exp);
31+
FREE_GMP_TEMP(temp_base);
32+
}

0 commit comments

Comments
 (0)