diff options
| author | Stanislav Malyshev <stas@php.net> | 2018-01-02 00:12:43 -0800 |
|---|---|---|
| committer | Stanislav Malyshev <stas@php.net> | 2018-01-02 00:12:43 -0800 |
| commit | 77298dee2ea85fa8e3ddd3ef984e0748d3737c6e (patch) | |
| tree | 3f78942ffe7937a180d684decc63a4de6ad29b68 | |
| parent | eb65916f7fb7091b4b1ba2817ea722d29e5cc7e7 (diff) | |
| parent | 4380ba7f9c75ace7f879835be024fac76275dbb0 (diff) | |
| download | php-git-77298dee2ea85fa8e3ddd3ef984e0748d3737c6e.tar.gz | |
Merge branch 'PHP-7.2'
* PHP-7.2:
Fix some int/long confusion issues in GMP
| -rw-r--r-- | ext/gmp/gmp.c | 6 | ||||
| -rw-r--r-- | ext/gmp/tests/gmp_setbit_long.phpt | 26 |
2 files changed, 31 insertions, 1 deletions
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index 45fbcdeef9..20d3d206e0 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -1696,7 +1696,7 @@ ZEND_FUNCTION(gmp_prob_prime) FETCH_GMP_ZVAL(gmpnum_a, gmpnumber_arg, temp_a); - RETVAL_LONG(mpz_probab_prime_p(gmpnum_a, reps)); + RETVAL_LONG(mpz_probab_prime_p(gmpnum_a, (int)reps)); FREE_GMP_TEMP(temp_a); } /* }}} */ @@ -2076,6 +2076,10 @@ ZEND_FUNCTION(gmp_setbit) php_error_docref(NULL, E_WARNING, "Index must be greater than or equal to zero"); RETURN_FALSE; } + if (index / GMP_NUMB_BITS >= INT_MAX ) { + php_error_docref(NULL, E_WARNING, "Index must be less than %ld * %ld", INT_MAX, GMP_NUMB_BITS); + RETURN_FALSE; + } gmpnum_a = GET_GMP_FROM_ZVAL(a_arg); diff --git a/ext/gmp/tests/gmp_setbit_long.phpt b/ext/gmp/tests/gmp_setbit_long.phpt new file mode 100644 index 0000000000..d0d0a3d989 --- /dev/null +++ b/ext/gmp/tests/gmp_setbit_long.phpt @@ -0,0 +1,26 @@ +--TEST-- +gmp_setbit() with large index +--SKIPIF-- +<?php if (!extension_loaded("gmp")) print "skip"; ?> +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> +<?php if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); ?> +--FILE-- +<?php + +$n = gmp_init("227200"); +for($a = 1<<30; $a > 0 && $a < 0x8000000000; $a <<= 2) { + $i = $a - 1; + printf("%X\n", $i); + gmp_setbit($n, $i, 1); +} +echo "Done\n"; +?> +--EXPECTF-- +3FFFFFFF +FFFFFFFF +3FFFFFFFF +FFFFFFFFF +3FFFFFFFFF + +Warning: gmp_setbit(): Index must be less than %d * %d in %s/gmp_setbit_long.php on line %d +Done
\ No newline at end of file |
