1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

179 Commits

Author SHA1 Message Date
Gina Peter Banyard
37549e4563 ext/gmp: Remove bool type coercions in tests 2025-06-21 22:19:37 +02:00
Florian Moser
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
brainpower
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
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
89eaa1fe5f ext/gmp: Refactor gmp_cmp() test 2024-11-27 15:10:49 +00:00
Gina Peter Banyard
fabfb6fe00 ext/gmp: Refactor gmp_divexact() and gmp_mod() to use custom ZPP specifier 2024-11-27 15:10:49 +00:00
Gina Peter Banyard
8e9b944a83 ext/gmp: Refactor gmp_div_(q|r)() to use new ZPP specifier 2024-11-27 15:10:49 +00:00
Gina Peter Banyard
1f5ba59b61 ext/gmp: Refactor gmp_div_qr() to use new ZPP specifier 2024-11-27 15:10:49 +00:00
Gina Peter Banyard
3964efd729 ext/gmp: Use new specifier for gmp_cmp()
It seems that this also now normalizes the return value
2024-11-27 15:10:49 +00:00
Gina Peter Banyard
10003a3f5d ext/gmp: Use new custom ZPP specifier 2024-11-27 15:10:49 +00:00
Gina Peter Banyard
57ae2c9530 ext/gmp: Split out non-existent inverse modulo cases 2024-11-27 15:10:49 +00:00
Christoph M. Becker
bd6b9df5dd Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16890: array_sum() with GMP can loose precision (LLP64)
2024-11-25 12:55:58 +01:00
Christoph M. Becker
cfcf5cfde8 Fix GH-16890: array_sum() with GMP can loose precision (LLP64)
We must use `mpz_fits_si_p()` instead of `mpz_fits_slong_p()` since the
latter is not suitable for LLP64 data models.

libgmp, however, does not define `mpz_fits_si_p()` (which is an mpir
addition), so we use `mpz_fits_slong_p()` there which should be fine.

Closes GH-16891.
2024-11-25 12:55:09 +01:00
Gina Peter Banyard
9e2367f29f Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  ext/gmp: Fix segfault when null is encountered on an overloaded operator
  ext/gmp: Add behavioural tests for operator overloading
2024-11-02 17:41:27 +00:00
Gina Peter Banyard
65d42342a1 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  ext/gmp: Fix segfault when null is encountered on an overloaded operator
  ext/gmp: Add behavioural tests for operator overloading
2024-11-02 17:40:41 +00:00
Gina Peter Banyard
5253647500 ext/gmp: Fix segfault when null is encountered on an overloaded operator
And various other issues like inconsistent type errors

Closes GH-16015
2024-11-02 17:36:32 +00:00
Gina Peter Banyard
fe02fd5095 ext/gmp: Add behavioural tests for operator overloading 2024-11-02 17:32:43 +00:00
David Carlier
9ee204f2e3 Merge branch 'PHP-8.3' into PHP-8.4 2024-10-25 14:05:16 +01:00
David Carlier
aa38bbed40 Merge branch 'PHP-8.2' into PHP-8.3 2024-10-25 14:05:07 +01:00
David Carlier
e0a0e216a9 ext/gmp: gmp_pow fix FPE with large values.
even without sanitizers, it is reproducible but with the following

```
<?php
$g = gmp_init(256);
var_dump(gmp_pow($g, PHP_INT_MAX));
```

we get this

```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==286922==ERROR: AddressSanitizer: FPE on unknown address 0x03e8000460ca (pc 0x7faf6c69de5c bp 0x400000000000004 sp 0x7ffe9843c740 T0)
    #0 0x7faf6c69de5c in __pthread_kill_implementation nptl/pthread_kill.c:44
    #1 0x7faf6c649c81 in __GI_raise ../sysdeps/posix/raise.c:26
    #2 0x7faf6db9386c in __gmp_exception (/lib/x86_64-linux-gnu/libgmp.so.10+0xd86c) (BuildId: 1af68a49fe041a5bb48a2915c3d47541f713bb38)
    #3 0x7faf6db938d3 in __gmp_overflow_in_mpz (/lib/x86_64-linux-gnu/libgmp.so.10+0xd8d3) (BuildId: 1af68a49fe041a5bb48a2915c3d47541f713bb38)
    #4 0x7faf6dbac95c in __gmpz_realloc (/lib/x86_64-linux-gnu/libgmp.so.10+0x2695c) (BuildId: 1af68a49fe041a5bb48a2915c3d47541f713bb38)
    #5 0x7faf6dba9038 in __gmpz_n_pow_ui (/lib/x86_64-linux-gnu/libgmp.so.10+0x23038) (BuildId: 1af68a49fe041a5bb48a2915c3d47541f713bb38)
    #6 0x5565ae1ccd9f in zif_gmp_pow /home/dcarlier/Contribs/php-src/ext/gmp/gmp.c:1286
    #7 0x5565aee96ea9 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER /home/dcarlier/Contribs/php-src/Zend/zend_vm_execute.h:1312
    #8 0x5565af144320 in execute_ex /home/dcarlier/Contribs/php-src/Zend/zend_vm_execute.h:56075
    #9 0x5565af160f07 in zend_execute /home/dcarlier/Contribs/php-src/Zend/zend_vm_execute.h:60439
    #10 0x5565aed6fafe in zend_execute_scripts /home/dcarlier/Contribs/php-src/Zend/zend.c:1842
    #11 0x5565aeae70a8 in php_execute_script /home/dcarlier/Contribs/php-src/main/main.c:2578
    #12 0x5565af532f4e in do_cli /home/dcarlier/Contribs/php-src/sapi/cli/php_cli.c:964
    #13 0x5565af535877 in main /home/dcarlier/Contribs/php-src/sapi/cli/php_cli.c:1334
    #14 0x7faf6c633d67 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #15 0x7faf6c633e24 in __libc_start_main_impl ../csu/libc-start.c:360
    #16 0x5565adc04040 in _start (/home/dcarlier/Contribs/php-src/sapi/cli/php+0x2604040) (BuildId: 949049955bdf8b7197390b1978a1dfc3ef6fdf38)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: FPE nptl/pthread_kill.c:44 in __pthread_kill_implementation
==286922==ABORTING
```

close GH-16384
2024-10-25 14:04:47 +01:00
David Carlier
bde23d0843 Merge branch 'PHP-8.3' into PHP-8.4 2024-10-20 21:44:04 +01:00
David Carlier
d6bac2f7e8 Merge branch 'PHP-8.2' into PHP-8.3 2024-10-20 21:43:51 +01:00
David Carlier
9ca68e037c Fix GH-16501: gmp_random_bits overflow.
we do the same calculation in advance as mpz_realloc overflow check to
avoid abort.

close GH-16503
2024-10-20 21:43:29 +01:00
Christoph M. Becker
b1fbdd8a67 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16411: gmp_export() can cause overflow
2024-10-15 15:59:53 +02:00
Christoph M. Becker
ea6f78eac8 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16411: gmp_export() can cause overflow
2024-10-15 15:58:21 +02:00
Christoph M. Becker
ab595c0764 Fix GH-16411: gmp_export() can cause overflow
We need not only to avoid the signed overflow while calculating
`bits_per_word` (reported issue), but also the unsigned overflow when
calculating `count`.  While the former has a fixed threshold, the
latter does not, since it also depends on the size in base 2.  Thus we
use a somewhat unconventional error message.

Closes GH-16418.
2024-10-15 15:57:17 +02:00
David Carlier
61d34b3ebc Merge branch 'PHP-8.3' into PHP-8.4 2024-10-13 14:26:59 +01:00
David Carlier
47c81462b8 Merge branch 'PHP-8.2' into PHP-8.3 2024-10-13 14:26:47 +01:00
David Carlier
d70b7811b0 ext/gmp: gmp_pow fix FPE with large values.
even without sanitizers, it is reproducible but with the following

```
<?php
$g = gmp_init(256);
var_dump(gmp_pow($g, PHP_INT_MAX));
```

we get this

```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==286922==ERROR: AddressSanitizer: FPE on unknown address 0x03e8000460ca (pc 0x7faf6c69de5c bp 0x400000000000004 sp 0x7ffe9843c740 T0)
    #0 0x7faf6c69de5c in __pthread_kill_implementation nptl/pthread_kill.c:44
    #1 0x7faf6c649c81 in __GI_raise ../sysdeps/posix/raise.c:26
    #2 0x7faf6db9386c in __gmp_exception (/lib/x86_64-linux-gnu/libgmp.so.10+0xd86c) (BuildId: 1af68a49fe041a5bb48a2915c3d47541f713bb38)
    #3 0x7faf6db938d3 in __gmp_overflow_in_mpz (/lib/x86_64-linux-gnu/libgmp.so.10+0xd8d3) (BuildId: 1af68a49fe041a5bb48a2915c3d47541f713bb38)
    #4 0x7faf6dbac95c in __gmpz_realloc (/lib/x86_64-linux-gnu/libgmp.so.10+0x2695c) (BuildId: 1af68a49fe041a5bb48a2915c3d47541f713bb38)
    #5 0x7faf6dba9038 in __gmpz_n_pow_ui (/lib/x86_64-linux-gnu/libgmp.so.10+0x23038) (BuildId: 1af68a49fe041a5bb48a2915c3d47541f713bb38)
    #6 0x5565ae1ccd9f in zif_gmp_pow /home/dcarlier/Contribs/php-src/ext/gmp/gmp.c:1286
    #7 0x5565aee96ea9 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER /home/dcarlier/Contribs/php-src/Zend/zend_vm_execute.h:1312
    #8 0x5565af144320 in execute_ex /home/dcarlier/Contribs/php-src/Zend/zend_vm_execute.h:56075
    #9 0x5565af160f07 in zend_execute /home/dcarlier/Contribs/php-src/Zend/zend_vm_execute.h:60439
    #10 0x5565aed6fafe in zend_execute_scripts /home/dcarlier/Contribs/php-src/Zend/zend.c:1842
    #11 0x5565aeae70a8 in php_execute_script /home/dcarlier/Contribs/php-src/main/main.c:2578
    #12 0x5565af532f4e in do_cli /home/dcarlier/Contribs/php-src/sapi/cli/php_cli.c:964
    #13 0x5565af535877 in main /home/dcarlier/Contribs/php-src/sapi/cli/php_cli.c:1334
    #14 0x7faf6c633d67 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #15 0x7faf6c633e24 in __libc_start_main_impl ../csu/libc-start.c:360
    #16 0x5565adc04040 in _start (/home/dcarlier/Contribs/php-src/sapi/cli/php+0x2604040) (BuildId: 949049955bdf8b7197390b1978a1dfc3ef6fdf38)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: FPE nptl/pthread_kill.c:44 in __pthread_kill_implementation
==286922==ABORTING
```
2024-10-13 14:26:29 +01:00
Peter Kokot
13f041163c Remove Travis artefacts (#15714)
Travis was suspended https://github.com/php/php-src/pull/15314

This removes 404 errored Travis image in README, travis configuration
directory and YAML file and usages in tests.

[skip ci]

Co-authored-by: Gina Peter Banyard <girgias@php.net>
2024-09-04 01:15:10 +02:00
Gina Peter Bnayard
d74b513f68 ext/gmp: Add test about manually (un)serializing 2024-08-12 17:30:10 +02:00
Saki Takamachi
60afeb5537 RFC: Change GMP bool cast behavior (#15151)
Implementation of "RFC: Change GMP bool cast behavior"

https://wiki.php.net/rfc/fix_up_bcmath_number_class

Co-authored-by: Tim Düsterhus <tim@bastelstu.be>
2024-07-31 00:41:49 +09:00
Gina Peter Banyard
a50adda19e ext/gmp: Make GMP class final (#15121)
* ext/gmp: Make GMP class final

RFC: https://wiki.php.net/rfc/gmp-final

* Update UPGRADING

Co-authored-by: Peter Kokot <peterkokot@gmail.com>

---------

Co-authored-by: Peter Kokot <peterkokot@gmail.com>
2024-07-28 13:03:26 +01:00
Gina Peter Banyard
13a5a8126e ext/gmp: Fix leading whitespace before explicit octal prefix 2024-04-23 23:39:48 +01:00
Gina Peter Banyard
4719ef258f ext/gmp: Improve error message 2024-04-23 23:39:48 +01:00
David CARLIER
bb1ef4fe21 ext/gmp: gmp_invert addressing todo. (#13654) 2024-03-09 23:10:12 +00:00
Máté Kocsis
7936c8085e Fix GH-8329 Print true/false instead of bool in error and debug messages (#8385) 2023-01-23 10:52:14 +01:00
George Peter Banyard
3280c70023 Merge branch 'PHP-8.2'
* PHP-8.2:
  Implement GMP::__construct()
2023-01-19 14:14:32 +00:00
Niels Dossche
4ea85d4044 Implement GMP::__construct()
Implements a proper constructor for GMP as discussed in both GH-10158 and https://externals.io/message/119216.
Fixes GH-10155

Closes GH-10225

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-01-19 14:13:34 +00:00
Tim Düsterhus
013e0f98ac Merge branch 'PHP-8.2'
* PHP-8.2:
  unserialize: Strictly check for `:{` at object start (#10214)
2023-01-12 19:57:22 +01:00
Tim Düsterhus
f2e8c5da90 unserialize: Strictly check for :{ at object start (#10214)
* unserialize: Strictly check for `:{` at object start

* unserialize: Update CVE tests

It's unlikely that the object syntax error contributed to the actual CVE. The
CVE is rather caused by the incorrect object serialization data of the `C`
format. Add a second string without such a syntax error to ensure that path is
still executed as well to ensure the CVE is absent.

* Fix test expectation in gmp/tests/bug74670.phpt

No changes to the input required, because the test actually is intended to
verify the behavior for a missing `}`, it's just that the report position changed.

* NEWS

* UPGRADING
2023-01-12 19:55:54 +01:00
George Peter Banyard
59f0fe5f16 Merge branch 'PHP-8.2' 2022-12-23 16:29:39 +00:00
Niels Dossche
a24659e70c Update test for changed behaviour of GMP constructor
Closed GH-10160

Signed-off-by: George Peter Banyard <girgias@php.net>
2022-12-23 16:29:14 +00:00
Tim Düsterhus
dd8de1e726 Promote unserialize() notices to warning (#9629)
* Unserialize: Migrate "Unexpected end of serialized data" to E_WARNING

* Unserialize: Migrate "Error at offset %d of %d bytes" to E_WARNING

* Unserialize: Migrate "%s is returned from __sleep() multiple times" to E_WARNING

* Add NEWS for “Promote unserialize() notices to warning”
2022-11-15 19:36:38 +01:00
George Peter Banyard
79b011bdd9 Merge branch 'PHP-8.1' into PHP-8.2 2022-09-13 11:35:12 +01:00