515 Commits
Author SHA1 Message Date
Dmytro Kulyk 67135cb97b gen_stub: Conditionally include zend_attributes.h to arginfo based on usage (#21570)
Headers required by the generated code (zend_attributes.h, zend_constants.h, zend_enum.h) are collected during generation and emitted as includes at the top of the arginfo file, with the same preprocessor conditions and PHP version guards as the code that needs them.

Removes the manual zend_attributes.h and zend_enum.h includes from sources that only needed them for the arginfo file they include.
2026-09-06 21:25:20 +02:00
NickSdot b74e0f749d ext/gmp: applied fixers to improve test robustness (#22987) 2026-08-01 23:06:14 +01:00
Weilin Du 6459664495 ext/gmp: expose the possibility of being a prime in gmp_prevprime (#22907)
Follow up #22807 to expose the "definitelyPrime" parameter in the
gmp_prevprime function to indicate the possibility of whether the outputted
number is actually a prime.
2026-07-29 03:09:44 +08:00
Weilin Du 081106ea44 ext/gmp: Add gmp_powm_sec() (#22852)
Expose mpz_powm_sec() to the userland, namely gmp_powm_sec().
2026-07-28 21:12:10 +08:00
Weilin Du 7abd4931d6 ext/gmp: Add gmp_prevprime() (#22807)
Expose mpz_prevprime() to the userland, namely gmp_prevprime().
2026-07-28 16:38:19 +08:00
Weilin Du f2b6b7fd3c ext/gmp: Fix GMP error messages using outdated parameter names (#22846)
The argument name in these error messages are different from what is claimed
in the documentation and public signatures.

Updated messages:

- gmp_root() and gmp_rootrem() now refer to argument 1 as $num instead of $a.
- gmp_random_range() now refers to argument 2 as $max instead of $maximum.
2026-07-21 19:39:06 +08:00
Weilin Du 988eb99c2c ext/gmp: Fix GMP accepting integer strings with NUL bytes (#22798)
convert_zstr_to_gmp() passes PHP strings to mpz_set_str(), which treats
input as a NUL-terminated C string. This allowed strings like
"123\0abc" to be accepted as 123.

Reject strings containing NUL bytes with zend_str_has_nul_byte()
before calling into GMP, preserving the existing "not an integer
string" error path.
2026-07-19 05:24:42 +08:00
Weilin Du e2ea940fc9 ext/gmp: Fix GMP operator RHS overflow for GMP values (#22656)
```php
<?php
$too_large = gmp_init("18446744073709551616");

var_dump(gmp_init(2) ** $too_large);
var_dump(gmp_init(2) << $too_large);
```
```
object(GMP)#3 (1) {
  ["num"]=>
  string(1) "1"
}
object(GMP)#2 (1) {
  ["num"]=>
  string(1) "2"
}
```
This PR fix the overflow by rejecting large gmp objects in these
calculation (throws ValueError)
2026-07-15 20:40:19 +08:00
Ilia Alshanetsky f04eaec41a Fix GH-22549: GMP compound pow/shift assign asserts on negative operand (#22582)
shift_operator_helper() wrote ZVAL_UNDEF(return_value) on the out-of-range
exponent/shift path, but for a compound assignment return_value aliases op1,
so pow_function's fallback then reached the scalar conversion with op1 set to
IS_UNDEF and hit ZEND_UNREACHABLE(). Drop the stray undef; the helper's other
error paths already return FAILURE without touching return_value, leaving the
operand intact for the thrown ValueError to propagate.

Fixes GH-22549
2026-07-06 15:26:00 -04:00
Weilin Du a59f6ec09b [skip ci] use die() instead of echo for 64-bit skip condition (#22299)
Follow up to #22247

SKIPIF condition should indeed exit the process to signal a problem.
2026-06-14 17:27:46 +08:00
Tim Düsterhus 69e023fd84 ext/*: Make X_from_obj(zend_object *obj) functions macros (#22183)
* ext/*: Make `X_from_obj(zend_object *obj)` functions macros

With the introduction of the `ZEND_CONTAINER_OF()` macro we can now preserve
whether or not the `zend_object *` is `const` when extracting the
class-specific struct. This change will allow to use `const zend_object *` in
more locations.

Changes performed with Coccinelle followed by some manual cleanup for comment
and whitespace formatting:

    @a@
    attribute name zend_always_inline;
    type T;
    identifier obj;
    identifier f;
    typedef zend_object;
    @@

     T* f(zend_object *obj) { return ZEND_CONTAINER_OF(obj, T, std); }
    + #define f(obj) ZEND_CONTAINER_OF(obj, T, std)

    @@
    identifier a.f;
    @@

    - f(...) { ... }

    @b@
    attribute name zend_always_inline;
    type T;
    identifier obj;
    identifier f;
    typedef zend_object;
    @@

     T* f(zend_object *obj) { return ZEND_CONTAINER_OF(obj, T, zo); }
    + #define f(obj) ZEND_CONTAINER_OF(obj, T, zo)

    @@
    identifier b.f;
    @@

    - f(...) { ... }

* sockets: Fix build

* odbc: Fix build
2026-06-01 10:21:03 +02:00
Tim Düsterhus 5212b816d2 zend_objects: Make old_object a const* in zend_objects_clone_members() (#22089)
* zend_objects: Make `old_object` a `const*` in `zend_objects_clone_members()`

* tree-wide: Make the original object `const` in `clone_obj` handlers
2026-05-19 14:16:03 +02:00
Tim Düsterhus ad7cce6527 zend_portability: Add ZEND_CONTAINER_OF() (#21903)
* zend_portability: Add `ZEND_CONTAINER_OF()`

* tree-wide: Use `ZEND_CONTAINER_OF()`

Changes made with Coccinelle:

    @@
    type T_container;
    identifier member;
    expression e;
    @@

    - (T_container *)(((char *)(e)) - offsetof(T_container, member))
    + ZEND_CONTAINER_OF(e, T_container, member)

    @@
    type T_container;
    identifier member;
    expression e;
    typedef uintptr_t;
    @@

    - (T_container *)(((uintptr_t)(e)) - offsetof(T_container, member))
    + ZEND_CONTAINER_OF(e, T_container, member)

    @@
    type T_container;
    identifier member;
    expression e;
    @@

    - (const T_container *)(((char *)(e)) - offsetof(T_container, member))
    + ZEND_CONTAINER_OF(e, T_container, member)

    @@
    type T_container;
    identifier member;
    expression e;
    typedef uintptr_t;
    @@

    - (const T_container *)(((uintptr_t)(e)) - offsetof(T_container, member))
    + ZEND_CONTAINER_OF(e, T_container, member)

* bcmath: Fix `get_bcmath_number_from_obj()` const-correctness

A follow-up change to the new `ZEND_CONTAINER_OF()` macro will preserve the
`const`-ness of the input pointer. By wrapping this macro inside a macro rather
an an inline function we can preserve the `const`-ness across all layers.

* zend_portability: Keep `const`-ness in `ZEND_CONTAINER_OF()`

* zend_portability: Add C++ version to `ZEND_CONTAINER_OF()`
2026-05-19 10:47:00 +02:00
Weilin Du 769441ba43 ext/gmp: Emit deprecation for precision-losing float RHS in ** / << / >> (#21945)
This is effectively fixing a missed case of the https://wiki.php.net/rfc/implicit-float-int-deprecate RFC.
2026-05-11 11:52:46 +01:00
Ilija Tovilo 529b145511 Merge branch 'PHP-8.5'
* PHP-8.5:
  GHSA-m8rr-4c36-8gq4: Consistently pass unsigned char to ctype.h functions
2026-05-06 13:11:01 +02:00
Ilija Tovilo b8dad9314c GHSA-m8rr-4c36-8gq4: Consistently pass unsigned char to ctype.h functions
Fixes GHSA-m8rr-4c36-8gq4
Fixes CVE-2026-7258
2026-05-06 13:10:12 +02:00
Ilija Tovilo dc9e21b81c GHSA-m8rr-4c36-8gq4: Consistently pass unsigned char to ctype.h functions
Fixes GHSA-m8rr-4c36-8gq4
Fixes CVE-2026-7258
2026-05-06 13:09:23 +02:00
Tim Düsterhus 7114314c5a tree-wide: Replace XtOffsetOf by its definition (#21899)
`offsetof()` is in `stddef.h` and thus always available. The extra macro is an
unnecessary layer of indirection.
2026-04-28 22:12:56 +02:00
David Carlier 617e4c38e0 ext/gmp: reject values larger than unsigned long in gmp_pow/binomial/root/rootrem and shift/pow operators.
Applies the gmp_fact() pattern (0236667bd9) to the remaining
zend_long -> gmp_ulong casts that could silently overflow on
LLP64 platforms.

gmp_powm() switches to zend_argument_error() with the correct
argument index ($modulus) for modulo-by-zero.

close GH-21812
2026-04-20 18:15:28 +01:00
David Carlier 0236667bd9 ext/gmp: gmp_fact() reject values larger than unsigned long.
close GH-21794
2026-04-18 17:42:24 +01:00
Ben Ramsey b2319244bc license-update: ext/gmp source headers
RFC: https://wiki.php.net/rfc/php_license_update
2026-04-11 21:20:54 -05:00
Tim Düsterhus 04f06e8cf2 zend_portability: Remove EMPTY_SWITCH_DEFAULT_CASE() (#20063)
There are several issues with this macro:

- It is incorrectly named: It's not an empty default case. It's an unreachable
  default case.
- It is hiding control flow in its definition, which can be confusing for
  humans and tools (such as Coccinelle) alike, because it looks like it would
  be a statement that belongs to the "current" case rather than opening a new
  one.

Since this macro is exactly as long as explicitly spelling out its definition
(excluding the useless `break;`), it is not even making the code any more
succinct.
2026-04-06 14:46:15 +02:00
Peter Kokot f17c5ad83b Windows build: Add new function CHECK_HEADER() (#21191)
The current function `CHECK_HEADER_ADD_INCLUDE()` automatically defines
`HAVE_<HEADER_NAME_H>` preprocessor macros, which makes it difficult to
sync with other build systems. Specially, if some `HAVE_` macro is used
in the code and this function defines this macro but Autotools doesn't.

The new `CHECK_HEADER()` function behaves similar except it doesn't
define the `HAVE_<HEADER_NAME_H>` preprocessor macro.

This removes the following unused compile definitions:

HAVE_ARGON2_H
HAVE_AVIF_H
HAVE_BZLIB_H
HAVE_CAPSTONE_CAPSTONE_H
HAVE_CURL_EASY_H
HAVE_DB_H
HAVE_DECODE_H
HAVE_DEPOT_H
HAVE_EDITLINE_READLINE_H
HAVE_ENCHANT_H
HAVE_ENCODE_H
HAVE_FFI_H
HAVE_FIREBIRD_INTERFACE_H
HAVE_FT2BUILD_H
HAVE_GD_H
HAVE_GLIB_H
HAVE_GMP_H
HAVE_HTTPD_H
HAVE_IBASE_H
HAVE_IR_IR_H
HAVE_KECCAKHASH_H
HAVE_LBER_H
HAVE_LDAP_H
HAVE_LIBEXSLT_EXSLT_H
HAVE_LIBINTL_H
HAVE_LIBPQ_FE_H
HAVE_LIBTIDY_TIDY_H
HAVE_LIBXML_PARSER_H
HAVE_LIBXML_TREE_H
HAVE_LIBXML_XMLWRITER_H
HAVE_LIBXSLT_XSLT_H
HAVE_LMDB_H
HAVE_MBSTRING_H
HAVE_MYSQL_H
HAVE_ONIGURUMA_H
HAVE_OPENSSL_SSL_H
HAVE_PNG_H
HAVE_SNMP_H
HAVE_SODIUM_H
HAVE_SQLITE3_H
HAVE_SQLITE3EXT_H
HAVE_SYBFRONT_H
HAVE_TIDY_H
HAVE_TIDY_TIDY_H
HAVE_TIDYBUFFIO_H
HAVE_TIMELIB_CONFIG_H
HAVE_UNICODE_USPOOF_H
HAVE_UNICODE_UTF_H
HAVE_XPM_H
HAVE_ZIP_H
HAVE_ZIPCONF_H
HAVE_ZLIB_H

The following compile definitions are defined explicitly:

- HAVE_ICONV_H
- HAVE_MSCOREE_H
- HAVE_SQL_H
- HAVE_SQLEXT_H

Additionally, the `SETUP_OPENSSL()` function doesn't accept the 6th
argument anymore.
2026-03-03 20:06:40 +01:00
Arnaud Le Blanc 65b4073922 Include the actual stub name in generated arginfo headers (#20993) 2026-01-21 20:57:00 +01:00
Tim Düsterhus ce566f2663 gmp: Use true / false instead of 1 / 0 when assigning to bool
Changes done with Coccinelle:

    @@
    bool b;
    @@

    - b = 0
    + b = false

    @@
    bool b;
    @@

    - b = 1
    + b = true
2025-09-24 18:51:40 +02:00
Gina Peter Banyard 37549e4563 ext/gmp: Remove bool type coercions in tests 2025-06-21 22:19:37 +02:00
Florian MoserandGina Peter Banyard 90da4821a2 ext/gmp: Add GMP ECC test (#18363)
Co-authored-by: Gina Peter Banyard <girgias@php.net>
2025-05-05 14:10:29 +01:00
Niels Dossche a142f10aa1 Don't evaluate GMP comparison multiple times (#18321)
ZEND_THREEWAY_COMPARE evaluates its operands multiple times.
2025-04-14 11:19:14 +02:00
Gina Peter Banyard c5edf94003 ext/gmp: Use zend_result type instead of int type 2025-04-11 22:53:20 +01:00
David CARLIER 05a155782b ext/gmp: use zend_object_alloc instead to initialize GMP instances. (#17822) 2025-02-15 19:09:36 +00:00
brainpowerandFlorian Moser 47942be18d ext/gmp: add test for uses of gmp_pow with number sizes commonly used in cryptography (#16896)
With common number sizes used there

---------

Co-authored-by: Florian Moser <git@famoser.ch>
2024-12-04 16:17:00 +00:00
Gina Peter Banyard f8547b1d97 ext/gmp: Check for valid bit index/start consistently 2024-11-29 16:55:38 +00:00
David Carlier 424ba0f2ff Finish reverting gmp_pow overflow check 2024-11-27 23:34:48 +00:00
Niels Dossche 0833f2376e Use specialised zend_new_pair() function to return array pairs in gmp
This is a bit faster, and more readable.
2024-11-27 23:34:23 +00:00
David Carlier 7b9b832be5 Merge branch 'PHP-8.4' 2024-11-27 19:55:04 +00:00
David Carlier bceb3adb42 Merge branch 'PHP-8.3' into PHP-8.4 2024-11-27 19:54:23 +00:00
David Carlier 841e54daee Merge branch 'PHP-8.2' into PHP-8.3 2024-11-27 19:54:06 +00:00
David Carlier 7e8d6f941c Revert "ext/gmp: gmp_pow fix FPE with large values."
This reverts commit d70b7811b0.
2024-11-27 19:52:07 +00:00
David Carlier 45140e527f Revert "ext/gmp: gmp_pow fix FPE with large values."
This reverts commit e0a0e216a9.
2024-11-27 19:52:04 +00:00
Gina Peter Banyard eaffa1150a ext/gmp: Compare object CE to gmp_ce directly
The GMP class is now final, therefore we don't need to use the instanceof function.
2024-11-27 19:08:50 +00:00
Gina Peter Banyard 313886e22b ext/gmp: Refactor op overloading for ZEND_BW_NOT
The only way for the do_operation object handler to be called for unary operations is when the zval is an object.
Therefore we know we have a zval of the correct type and there is no need to check for it.
2024-11-27 19:08:50 +00:00
Gina Peter Banyard 0800c68be6 ext/gmp: Remove redundant parenthesis 2024-11-27 15:10:49 +00:00
Gina Peter Banyard 0b5b9472ff Normalize gmp_cmp() to -1/0/+1 2024-11-27 15:10:49 +00:00
Gina Peter Banyard 89eaa1fe5f ext/gmp: Refactor gmp_cmp() test 2024-11-27 15:10:49 +00:00
Gina Peter Banyard 601f6cd54d ext/gmp: Use new parsing mechanism in comparison operator overloading
This removes the last usages of the old GMP_FETCH API
2024-11-27 15:10:49 +00:00
Gina Peter Banyard 92ff44da12 ext/gmp: Use new parsing API in shift helper 2024-11-27 15:10:49 +00:00
Gina Peter Banyard 0831608c8b ext/gmp: Add weak mode support for parsing 2024-11-27 15:10:49 +00:00
Gina Peter Banyard 27044108d3 ext/gmp: Convert GMP operator overloading to new parsing mechanism 2024-11-27 15:10:49 +00:00
Gina Peter Banyard 8b2cd8fd2d ext/gmp: Start refactoring operator overloading to use new parsing mechanism 2024-11-27 15:10:49 +00:00
Gina Peter Banyard 2681da4531 ext/gmp: Refactor gmp_fact() to use new ZPP specifier
Not sure it is the best approach to do this one however
2024-11-27 15:10:49 +00:00