Skip to content

Commit 3380de9

Browse files
committed
Fixed bug #65304 (Use of max int in array_sum)
1 parent cc91fbe commit 3380de9

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PHP NEWS
33
?? ??? 2013, PHP 5.4.19
44

55
- Core.
6+
. Fixed bug #65304 (Use of max int in array_sum). (Laruence)
67
. Fixed bug #65291 (get_defined_constants() causes PHP to crash in a very
78
limited case). (Arpad)
89
. Improve fix for bug #63186 (compile failure on netbsd). (Matteo)

ext/standard/array.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4037,17 +4037,7 @@ PHP_FUNCTION(array_sum)
40374037
entry_n = **entry;
40384038
zval_copy_ctor(&entry_n);
40394039
convert_scalar_to_number(&entry_n TSRMLS_CC);
4040-
4041-
if (Z_TYPE(entry_n) == IS_LONG && Z_TYPE_P(return_value) == IS_LONG) {
4042-
dval = (double)Z_LVAL_P(return_value) + (double)Z_LVAL(entry_n);
4043-
if ( (double)LONG_MIN <= dval && dval <= (double)LONG_MAX ) {
4044-
Z_LVAL_P(return_value) += Z_LVAL(entry_n);
4045-
continue;
4046-
}
4047-
}
4048-
convert_to_double(return_value);
4049-
convert_to_double(&entry_n);
4050-
Z_DVAL_P(return_value) += Z_DVAL(entry_n);
4040+
fast_add_function(return_value, return_value, &entry_n TSRMLS_CC);
40514041
}
40524042
}
40534043
/* }}} */
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #65304 (Use of max int in array_sum)
3+
--FILE--
4+
<?php
5+
var_dump(array_sum(array(PHP_INT_MAX, 1)));
6+
var_dump(PHP_INT_MAX + 1);
7+
?>
8+
--EXPECTF--
9+
float(%s)
10+
float(%s)

0 commit comments

Comments
 (0)