Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bb55397
Make zpp fail if NaN passed for int, or out-of-range float for non-ca…
hikari-no-yume Sep 22, 2014
25eb496
Fixed broken tests
hikari-no-yume Sep 22, 2014
a401db2
Fixed ext/date tests broken by zpp error on overflow
hikari-no-yume Sep 22, 2014
820a464
Mark said ext/date tests as 32-bit only
hikari-no-yume Sep 22, 2014
71566b9
Merge branch 'master' into zppFailOnOverflow
hikari-no-yume Nov 1, 2014
d22f3b1
Merge branch 'master' into zppFailOnOverflow
hikari-no-yume Nov 8, 2014
b707793
Fixed some 32-bit tests
hikari-no-yume Nov 9, 2014
26bb809
Fixed more 32-bit tests
hikari-no-yume Nov 9, 2014
5b52fb5
Marked tests as 32-bit
hikari-no-yume Nov 9, 2014
344eba1
Fixes iconv tests
ralt Nov 9, 2014
62f6c3c
Fixes posix tests
ralt Nov 9, 2014
df1b722
Fixes simplexml test
ralt Nov 9, 2014
cc35388
Merge branch 'zppFailOnOverflow' of github.com:Ralt/php-src into zppF…
hikari-no-yume Nov 11, 2014
f574ad1
skip tests on 32-bit
hikari-no-yume Nov 28, 2014
0885805
skip posix 32-bit
hikari-no-yume Nov 28, 2014
55e1c03
skip simplexml
hikari-no-yume Nov 28, 2014
ebaa423
Skip buncha tests on 32-bit
hikari-no-yume Nov 29, 2014
65c8edd
Fix more 32-bit tests
hikari-no-yume Nov 29, 2014
01554bf
Merge branch 'master' into zppFailOnOverflow
hikari-no-yume Nov 29, 2014
d19ce51
Fixed copy-and-paste error
hikari-no-yume Nov 29, 2014
f90b877
Refactor ZEND_LONG_MAX/MIN checks into ZEND_DOUBLE_FITS_LONG()
hikari-no-yume Nov 29, 2014
175844c
Fixed gd test
hikari-no-yume Nov 29, 2014
d5afeef
Fix MySQLi tests
hikari-no-yume Nov 29, 2014
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,16 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons
if ((type = is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), p, &d, -1)) == 0) {
return "long";
} else if (type == IS_DOUBLE) {
if (c == 'L') {
if (d > ZEND_LONG_MAX) {
*p = ZEND_LONG_MAX;
break;
} else if (d < ZEND_LONG_MIN) {
*p = ZEND_LONG_MIN;
break;
if (zend_isnan(d)) {
return "long";
}
if (!ZEND_DOUBLE_FITS_LONG(d)) {
if (c == 'L') {
*p = (d > 0) ? ZEND_LONG_MAX : ZEND_LONG_MIN;
} else {
return "long";
}
break;
}

*p = zend_dval_to_lval(d);
Expand All @@ -420,14 +422,16 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons
break;

case IS_DOUBLE:
if (c == 'L') {
if (Z_DVAL_P(arg) > ZEND_LONG_MAX) {
*p = ZEND_LONG_MAX;
break;
} else if (Z_DVAL_P(arg) < ZEND_LONG_MIN) {
*p = ZEND_LONG_MIN;
break;
if (zend_isnan(Z_DVAL_P(arg))) {
return "long";
}
if (!ZEND_DOUBLE_FITS_LONG(Z_DVAL_P(arg))) {
if (c == 'L') {
*p = (Z_DVAL_P(arg) > 0) ? ZEND_LONG_MAX : ZEND_LONG_MIN;
} else {
return "long";
}
break;
}
case IS_NULL:
case IS_FALSE:
Expand Down
27 changes: 19 additions & 8 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -1064,10 +1064,16 @@ static zend_always_inline int _z_param_long(zval *arg, zend_long *dest, zend_boo
if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
*dest = Z_LVAL_P(arg);
} else if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) {
if (strict && UNEXPECTED(Z_DVAL_P(arg) > ZEND_LONG_MAX)) {
*dest = ZEND_LONG_MAX;
} else if (strict && UNEXPECTED(Z_DVAL_P(arg) < ZEND_LONG_MIN)) {
*dest = ZEND_LONG_MIN;
if (UNEXPECTED(zend_isnan(Z_DVAL_P(arg)))) {
return 0;
}
if (UNEXPECTED(!ZEND_DOUBLE_FITS_LONG(Z_DVAL_P(arg)))) {
/* Ironically, the strict parameter makes zpp *non*-strict here */
if (strict) {
*dest = (Z_DVAL_P(arg) > 0) ? ZEND_LONG_MAX : ZEND_LONG_MIN;
} else {
return 0;
}
} else {
*dest = zend_dval_to_lval(Z_DVAL_P(arg));
}
Expand All @@ -1077,10 +1083,15 @@ static zend_always_inline int _z_param_long(zval *arg, zend_long *dest, zend_boo

if (UNEXPECTED((type = is_numeric_str_function(Z_STR_P(arg), dest, &d)) != IS_LONG)) {
if (EXPECTED(type != 0)) {
if (strict && UNEXPECTED(d > ZEND_LONG_MAX)) {
*dest = ZEND_LONG_MAX;
} else if (strict && UNEXPECTED(d < ZEND_LONG_MIN)) {
*dest = ZEND_LONG_MIN;
if (UNEXPECTED(zend_isnan(d))) {
return 0;
}
if (UNEXPECTED(!ZEND_DOUBLE_FITS_LONG(d))) {
if (strict) {
*dest = (d > 0) ? ZEND_LONG_MAX : ZEND_LONG_MIN;
} else {
return 0;
}
} else {
*dest = zend_dval_to_lval(d);
}
Expand Down
12 changes: 9 additions & 3 deletions Zend/zend_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ ZEND_API zend_uchar _is_numeric_string_ex(const char *str, size_t length, zend_l

END_EXTERN_C()

#if SIZEOF_ZEND_LONG == 4
# define ZEND_DOUBLE_FITS_LONG(d) (!((d) > ZEND_LONG_MAX || (d) < ZEND_LONG_MIN))
#else
/* >= as (double)ZEND_LONG_MAX is outside signed range */
# define ZEND_DOUBLE_FITS_LONG(d) (!((d) >= ZEND_LONG_MAX || (d) < ZEND_LONG_MIN))
#endif

#if ZEND_DVAL_TO_LVAL_CAST_OK
static zend_always_inline zend_long zend_dval_to_lval(double d)
{
Expand All @@ -103,7 +110,7 @@ static zend_always_inline zend_long zend_dval_to_lval(double d)
{
if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) {
return 0;
} else if (d > ZEND_LONG_MAX || d < ZEND_LONG_MIN) {
} else if (!ZEND_DOUBLE_FITS_LONG(d)) {
double two_pow_32 = pow(2., 32.),
dmod;

Expand All @@ -122,8 +129,7 @@ static zend_always_inline zend_long zend_dval_to_lval(double d)
{
if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) {
return 0;
/* >= as (double)ZEND_LONG_MAX is outside signed range */
} else if (d >= ZEND_LONG_MAX || d < ZEND_LONG_MIN) {
} else if (!ZEND_DOUBLE_FITS_LONG(d)) {
double two_pow_64 = pow(2., 64.),
dmod;

Expand Down
7 changes: 4 additions & 3 deletions ext/date/tests/bug36988.phpt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
--TEST--
Bug #36988 (mktime freezes on long numbers)
--SKIPIF--
<?php if (PHP_INT_SIZE != 4) echo "skip this test is for 32-bit only"; ?>
--FILE--
<?php
date_default_timezone_set('GMT');
$start = microtime(true);
$a = mktime(1, 1, 1, 1, 1, 11111111111);
echo (microtime(true) - $start) < 1 ? "smaller than one second" : "more than a second";
?>
--EXPECT--
smaller than one second
--EXPECTF--
Warning: mktime() expects parameter 6 to be long, double given in %s on line %d
12 changes: 7 additions & 5 deletions ext/date/tests/bug52062.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Bug #52062 (large timestamps with DateTime::getTimestamp and DateTime::setTimestamp) (32 bit)
--SKIPIF--
<?php
if (PHP_INT_SIZE == 8) die('skip 32-bit only');
if (PHP_INT_SIZE != 4) die('skip 32-bit only');
?>
--INI--
date.timezone=UTC
Expand All @@ -20,10 +20,12 @@ var_dump($d->getTimestamp());
$i = new DateInterval('PT100000000000S');
var_dump($i->format('%s'));
?>
--EXPECT--
--EXPECTF--
string(32) "5138-11-16 09:46:40 100000000000"
bool(false)
string(12) "100000000000"
string(30) "2008-07-11 04:56:32 1215752192"
int(1215752192)
string(10) "1215752192"

Warning: DateTime::setTimestamp() expects parameter 1 to be long, double given in %s on line %d
string(32) "5138-11-16 09:46:40 100000000000"
bool(false)
string(10) "1215752192"
6 changes: 4 additions & 2 deletions ext/date/tests/date_sunrise_variation2.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Test date_sunrise() function : usage variation - Passing unexpected values to second argument format.
--SKIPIF--
<?php if (PHP_INT_SIZE != 4) echo "skip this test is for 32-bit only"; ?>
--FILE--
<?php
/* Prototype : mixed date_sunrise(mixed time [, int format [, float latitude [, float longitude [, float zenith [, float gmt_offset]]]]])
Expand Down Expand Up @@ -114,12 +116,12 @@ bool(false)

--float 12.3456789000e10--

Warning: date_sunrise(): Wrong return format given, pick one of SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING or SUNFUNCS_RET_DOUBLE in %s on line %d
Warning: date_sunrise() expects parameter 2 to be long, double given in %s on line %d
bool(false)

--float -12.3456789000e10--

Warning: date_sunrise(): Wrong return format given, pick one of SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING or SUNFUNCS_RET_DOUBLE in %s on line %d
Warning: date_sunrise() expects parameter 2 to be long, double given in %s on line %d
bool(false)

--float .5--
Expand Down
40 changes: 27 additions & 13 deletions ext/date/tests/date_sunrise_variation9.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Test date_sunrise() function : usage variation - Passing high positive and negative float values to time argument.
--SKIPIF--
<?php if (PHP_INT_SIZE != 4) echo "skip this test is for 32-bit only"; ?>
--FILE--
<?php
/* Prototype : mixed date_sunrise(mixed time [, int format [, float latitude [, float longitude [, float zenith [, float gmt_offset]]]]])
Expand Down Expand Up @@ -32,16 +34,28 @@ var_dump( date_sunrise($time, SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude, $ze

?>
===DONE===
--EXPECTREGEX--
\*\*\* Testing date_sunrise\(\) : usage variation \*\*\*

-- Testing date_sunrise\(\) function by passing float 12.3456789000e10 value to time --
string\(5\) "(07:34|07:49)"
float\((7.566[0-9]*|7.821[0-9]*)\)
int\((-1097256359|123456811756)\)

-- Testing date_sunrise\(\) function by passing float -12.3456789000e10 value to time --
string\(5\) "(07:42|08:48|08:04)"
float\((7.713[0-9]*|8.810[0-9]*|8.074[0-9]*)\)
int\((1097304168|-2147443882|-123456761731)\)
===DONE===
--EXPECTF--
*** Testing date_sunrise() : usage variation ***

-- Testing date_sunrise() function by passing float 12.3456789000e10 value to time --

Warning: date_sunrise() expects parameter 1 to be long, double given in %s on line %d
bool(false)

Warning: date_sunrise() expects parameter 1 to be long, double given in %s on line %d
bool(false)

Warning: date_sunrise() expects parameter 1 to be long, double given in %s on line %d
bool(false)

-- Testing date_sunrise() function by passing float -12.3456789000e10 value to time --

Warning: date_sunrise() expects parameter 1 to be long, double given in %s on line %d
bool(false)

Warning: date_sunrise() expects parameter 1 to be long, double given in %s on line %d
bool(false)

Warning: date_sunrise() expects parameter 1 to be long, double given in %s on line %d
bool(false)
===DONE===
8 changes: 5 additions & 3 deletions ext/date/tests/date_sunset_variation2.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Test date_sunset() function : usage variation - Passing unexpected values to second argument format.
--SKIPIF--
<?php if (PHP_INT_SIZE != 4) echo "skip this test is for 32-bit only"; ?>
--FILE--
<?php
/* Prototype : mixed date_sunset(mixed time [, int format [, float latitude [, float longitude [, float zenith [, float gmt_offset]]]]])
Expand Down Expand Up @@ -114,12 +116,12 @@ bool(false)

--float 12.3456789000e10--

Warning: date_sunset(): Wrong return format given, pick one of SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING or SUNFUNCS_RET_DOUBLE in %s on line %d
Warning: date_sunset() expects parameter 2 to be long, double given in %s on line %d
bool(false)

--float -12.3456789000e10--

Warning: date_sunset(): Wrong return format given, pick one of SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING or SUNFUNCS_RET_DOUBLE in %s on line %d
Warning: date_sunset() expects parameter 2 to be long, double given in %s on line %d
bool(false)

--float .5--
Expand Down Expand Up @@ -208,4 +210,4 @@ int(1218199253)

--unset var--
int(1218199253)
===DONE===
===DONE===
38 changes: 26 additions & 12 deletions ext/date/tests/date_sunset_variation9.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Test date_sunset() function : usage variation - Passing high positive and negative float values to time argument.
--SKIPIF--
<?php if (PHP_INT_SIZE != 4) echo "skip this test is for 32-bit only"; ?>
--FILE--
<?php
/* Prototype : mixed date_sunset(mixed time [, int format [, float latitude [, float longitude [, float zenith [, float gmt_offset]]]]])
Expand Down Expand Up @@ -32,16 +34,28 @@ var_dump( date_sunset($time, SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude, $zen

?>
===DONE===
--EXPECTREGEX--
\*\*\* Testing date_sunset\(\) : usage variation \*\*\*

-- Testing date_sunset\(\) function by passing float 12.3456789000e10 value to time --
string\(5\) "(19:49|19:28)"
float\((19.830[0-9]*|19.830[0-9]*|19.480[0-9]*)\)
int\((-1097212211|123456853728)\)

-- Testing date_sunset\(\) function by passing float -12.3456789000e10 value to time --
string\(5\) "(19:03|18:12|18:48)"
float\((19.056[0-9]*|18.213[0-9]*|18.808[0-9]*)\)
int\((1097345002|-2147410031|-123456723090)\)
--EXPECTF--
*** Testing date_sunset() : usage variation ***

-- Testing date_sunset() function by passing float 12.3456789000e10 value to time --

Warning: date_sunset() expects parameter 1 to be long, double given in %s on line %d
bool(false)

Warning: date_sunset() expects parameter 1 to be long, double given in %s on line %d
bool(false)

Warning: date_sunset() expects parameter 1 to be long, double given in %s on line %d
bool(false)

-- Testing date_sunset() function by passing float -12.3456789000e10 value to time --

Warning: date_sunset() expects parameter 1 to be long, double given in %s on line %d
bool(false)

Warning: date_sunset() expects parameter 1 to be long, double given in %s on line %d
bool(false)

Warning: date_sunset() expects parameter 1 to be long, double given in %s on line %d
bool(false)
===DONE===
65 changes: 12 additions & 53 deletions ext/date/tests/getdate_variation7.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Test getdate() function : usage variation - Passing high positive and negative float values to timestamp.
--SKIPIF--
<?php if (PHP_INT_SIZE != 4) echo "skip this test is for 32-bit only"; ?>
--FILE--
<?php
/* Prototype : array getdate([int timestamp])
Expand All @@ -20,59 +22,16 @@ $timestamp = -12.3456789000e10;
var_dump( getdate($timestamp) );
?>
===DONE===
--EXPECTREGEX--
--EXPECTF--
*** Testing getdate() : usage variation ***

\*\*\* Testing getdate\(\) : usage variation \*\*\*
-- Testing getdate() function by passing float 12.3456789000e10 value to timestamp --

-- Testing getdate\(\) function by passing float 12.3456789000e10 value to timestamp --
array\(11\) {
\["seconds"\]=>
int\((36|0)\)
\["minutes"\]=>
int\((43|0)\)
\["hours"\]=>
int\((10|6)\)
\["mday"\]=>
int\((26|11)\)
\["wday"\]=>
int\((2|6)\)
\["mon"\]=>
int\(3\)
\["year"\]=>
int\((1935|5882)\)
\["yday"\]=>
int\((84|69)\)
\["weekday"\]=>
string\((7|8)\) "(Tuesday|Saturday)"
\["month"\]=>
string\(5\) "March"
\[0\]=>
int\((-1097262584|123456789000)\)
}
Warning: getdate() expects parameter 1 to be long, double given in %s on line %d
bool(false)

-- Testing getdate\(\) function by passing float -12.3456789000e10 value to timestamp --
array\(11\) {
\["seconds"\]=>
int\((44|12|20)\)
\["minutes"\]=>
int\((39|23)\)
\["hours"\]=>
int\((0|2|5)\)
\["mday"\]=>
int\((9|14|23)\)
\["wday"\]=>
int\((6|-4)\)
\["mon"\]=>
int\((10|12)\)
\["year"\]=>
int\((2004|1901|-1943)\)
\["yday"\]=>
int\((282|347|295)\)
\["weekday"\]=>
string\((8|7)\) "(Saturday|Unknown)"
\["month"\]=>
string\((7|8)\) "(October|December)"
\[0\]=>
int\((1097262584|-2147483648|-123456789000)\)
}
===DONE===
-- Testing getdate() function by passing float -12.3456789000e10 value to timestamp --

Warning: getdate() expects parameter 1 to be long, double given in %s on line %d
bool(false)
===DONE===
Loading