Skip to content

Commit 2cc7df9

Browse files
committed
Merge branch 'master' into jit-dynasm
* master: Use system libzip by default Not sure why these lines are removed :< Update NEWS Fixed bug #75152 (signed integer overflow in parse_iv) Fixed bug #73730 (textdomain(null) throws in strict mode) They should always be equal (zend_call_graph.c:php#109) Optimize truncation to zero scale in bc_raisemod() Fix bug75178.phpt on Windows Fixed signature Fixed bug #75178 (bcpowmod() misbehaves for non-integer base or modulus) Added gd func infos Added fileinfo func infos Remove unused member
2 parents d93e7ea + 8857161 commit 2cc7df9

File tree

16 files changed

+303
-113
lines changed

16 files changed

+303
-113
lines changed

ext/bcmath/libbcmath/src/bcmath.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ typedef struct bc_struct
4242
int n_len; /* The number of digits before the decimal point. */
4343
int n_scale; /* The number of digits after the decimal point. */
4444
int n_refs; /* The number of pointers to this number. */
45-
bc_num n_next; /* Linked list for available list. */
4645
char *n_ptr; /* The pointer to the actual storage.
4746
If NULL, n_value points to the inside of
4847
another number (bc_multiply...) and should

ext/bcmath/libbcmath/src/init.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ _bc_new_num_ex (length, scale, persistent)
5151
}
5252
/* PHP Change: malloc() -> pemalloc(), removed free_list code */
5353
temp = (bc_num) safe_pemalloc (1, sizeof(bc_struct)+length, scale, persistent);
54-
#if 0
55-
if (_bc_Free_list != NULL) {
56-
temp = _bc_Free_list;
57-
_bc_Free_list = temp->n_next;
58-
} else {
59-
temp = (bc_num) pemalloc (sizeof(bc_struct), persistent);
60-
}
61-
#endif
6254
temp->n_sign = PLUS;
6355
temp->n_len = length;
6456
temp->n_scale = scale;
@@ -86,10 +78,6 @@ _bc_free_num_ex (num, persistent)
8678
/* PHP Change: free() -> pefree(), removed free_list code */
8779
pefree ((*num)->n_ptr, persistent);
8880
pefree(*num, persistent);
89-
#if 0
90-
(*num)->n_next = _bc_Free_list;
91-
_bc_Free_list = *num;
92-
#endif
9381
}
9482
*num = NULL;
9583
}

ext/bcmath/libbcmath/src/raisemod.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,32 @@
3838
#include "bcmath.h"
3939
#include "private.h"
4040

41+
42+
/* Truncate a number to zero scale. To avoid sharing issues (refcount and
43+
shared n_value) the number is copied, this copy is truncated, and the
44+
original number is "freed". */
45+
46+
static void
47+
_bc_truncate (bc_num *num)
48+
{
49+
bc_num temp;
50+
51+
temp = bc_new_num ((*num)->n_len, 0);
52+
temp->n_sign = (*num)->n_sign;
53+
memcpy (temp->n_value, (*num)->n_value, (*num)->n_len);
54+
bc_free_num (num);
55+
*num = temp;
56+
}
57+
58+
4159
/* Raise BASE to the EXPO power, reduced modulo MOD. The result is
4260
placed in RESULT. If a EXPO is not an integer,
4361
only the integer part is used. */
4462

4563
int
4664
bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale)
4765
{
48-
bc_num power, exponent, parity, temp;
66+
bc_num power, exponent, modulus, parity, temp;
4967
int rscale;
5068

5169
/* Check for correct numbers. */
@@ -55,27 +73,34 @@ bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale)
5573
/* Set initial values. */
5674
power = bc_copy_num (base);
5775
exponent = bc_copy_num (expo);
76+
modulus = bc_copy_num (mod);
5877
temp = bc_copy_num (BCG(_one_));
5978
bc_init_num(&parity);
6079

6180
/* Check the base for scale digits. */
62-
if (base->n_scale != 0)
81+
if (power->n_scale != 0)
82+
{
6383
bc_rt_warn ("non-zero scale in base");
84+
_bc_truncate (&power);
85+
}
6486

6587
/* Check the exponent for scale digits. */
6688
if (exponent->n_scale != 0)
6789
{
6890
bc_rt_warn ("non-zero scale in exponent");
69-
bc_divide (exponent, BCG(_one_), &exponent, 0); /*truncate */
91+
_bc_truncate (&exponent);
7092
}
7193

7294
/* Check the modulus for scale digits. */
73-
if (mod->n_scale != 0)
95+
if (modulus->n_scale != 0)
96+
{
7497
bc_rt_warn ("non-zero scale in modulus");
98+
_bc_truncate (&modulus);
99+
}
75100

76101
/* Do the calculation. */
77-
rscale = MAX(scale, base->n_scale);
78-
if ( !bc_compare(mod, BCG(_one_)) )
102+
rscale = MAX(scale, power->n_scale);
103+
if ( !bc_compare(modulus, BCG(_one_)) )
79104
{
80105
temp = bc_new_num (1, scale);
81106
}
@@ -87,17 +112,18 @@ bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale)
87112
if ( !bc_is_zero(parity) )
88113
{
89114
bc_multiply (temp, power, &temp, rscale);
90-
(void) bc_modulo (temp, mod, &temp, scale);
115+
(void) bc_modulo (temp, modulus, &temp, scale);
91116
}
92117

93118
bc_multiply (power, power, &power, rscale);
94-
(void) bc_modulo (power, mod, &power, scale);
119+
(void) bc_modulo (power, modulus, &power, scale);
95120
}
96121
}
97122

98123
/* Assign the value. */
99124
bc_free_num (&power);
100125
bc_free_num (&exponent);
126+
bc_free_num (&modulus);
101127
bc_free_num (result);
102128
bc_free_num (&parity);
103129
*result = temp;

ext/bcmath/tests/bug75178-win32.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #75178 (bcpowmod() misbehaves for non-integer base or modulus)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension is not available');
6+
if (substr(PHP_OS, 0, 3) != 'WIN') {
7+
die('skip valid only for windows');
8+
}
9+
?>
10+
--FILE--
11+
<?php
12+
var_dump(bcpowmod('4.1', '4', '3', 3));
13+
var_dump(bcpowmod('4', '4', '3.1', 3));
14+
?>
15+
===DONE===
16+
--EXPECT--
17+
string(5) "1.000"
18+
string(5) "1.000"
19+
===DONE===
20+
bc math warning: non-zero scale in base
21+
bc math warning: non-zero scale in modulus

ext/bcmath/tests/bug75178.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #75178 (bcpowmod() misbehaves for non-integer base or modulus)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension is not available');
6+
if (substr(PHP_OS, 0, 3) == 'WIN') {
7+
die('skip Not valid for windows');
8+
}
9+
?>
10+
--FILE--
11+
<?php
12+
var_dump(bcpowmod('4.1', '4', '3', 3));
13+
var_dump(bcpowmod('4', '4', '3.1', 3));
14+
?>
15+
===DONE===
16+
--EXPECT--
17+
bc math warning: non-zero scale in base
18+
string(5) "1.000"
19+
bc math warning: non-zero scale in modulus
20+
string(5) "1.000"
21+
===DONE===

ext/gd/gd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,7 +3036,7 @@ PHP_FUNCTION(imagecolorexact)
30363036
}
30373037
/* }}} */
30383038

3039-
/* {{{ proto void imagecolorset(resource im, int col, int red, int green, int blue)
3039+
/* {{{ proto bool imagecolorset(resource im, int col, int red, int green, int blue)
30403040
Set the color for the specified palette index */
30413041
PHP_FUNCTION(imagecolorset)
30423042
{
@@ -4634,7 +4634,7 @@ PHP_FUNCTION(imageconvolution)
46344634
/* }}} */
46354635
/* End section: Filters */
46364636

4637-
/* {{{ proto void imageflip(resource im, int mode)
4637+
/* {{{ proto bool imageflip(resource im, int mode)
46384638
Flip an image (in place) horizontally, vertically or both directions. */
46394639
PHP_FUNCTION(imageflip)
46404640
{
@@ -4692,7 +4692,7 @@ PHP_FUNCTION(imageantialias)
46924692
}
46934693
/* }}} */
46944694

4695-
/* {{{ proto void imagecrop(resource im, array rect)
4695+
/* {{{ proto resource imagecrop(resource im, array rect)
46964696
Crop an image using the given coordinates and size, x, y, width and height. */
46974697
PHP_FUNCTION(imagecrop)
46984698
{
@@ -4749,7 +4749,7 @@ PHP_FUNCTION(imagecrop)
47494749
}
47504750
/* }}} */
47514751

4752-
/* {{{ proto void imagecropauto(resource im [, int mode [, float threshold [, int color]]])
4752+
/* {{{ proto resource imagecropauto(resource im [, int mode [, float threshold [, int color]]])
47534753
Crop an image automatically using one of the available modes. */
47544754
PHP_FUNCTION(imagecropauto)
47554755
{

ext/gettext/gettext.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,16 @@ PHP_MINFO_FUNCTION(php_gettext)
161161
Set the textdomain to "domain". Returns the current domain */
162162
PHP_NAMED_FUNCTION(zif_textdomain)
163163
{
164-
char *domain, *domain_name, *retval;
165-
size_t domain_len;
164+
char *domain = NULL, *domain_name, *retval;
165+
size_t domain_len = 0;
166166

167-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &domain, &domain_len) == FAILURE) {
167+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &domain, &domain_len) == FAILURE) {
168168
return;
169169
}
170170

171171
PHP_GETTEXT_DOMAIN_LENGTH_CHECK
172172

173-
if (strcmp(domain, "") && strcmp(domain, "0")) {
173+
if (domain != NULL && strcmp(domain, "") && strcmp(domain, "0")) {
174174
domain_name = domain;
175175
} else {
176176
domain_name = NULL;

ext/gettext/tests/bug73730.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #73730 (textdomain(null) throws in strict mode)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gettext')) die('skip gettext extension is not available');
6+
?>
7+
--FILE--
8+
<?php
9+
declare(strict_types=1);
10+
11+
var_dump(textdomain(null));
12+
?>
13+
===DONE===
14+
--EXPECT--
15+
string(8) "messages"
16+
===DONE===

0 commit comments

Comments
 (0)