stas Wed, 01 Sep 2010 20:34:59 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=302982
Log:
Fix bug #50590 - IntlDateFormatter::parse result is limited to the integer range
Bug: http://bugs.php.net/50590 (Assigned) IntlDateFormatter::parse result is
limited to the integer range
Changed paths:
U php/php-src/branches/PHP_5_3/NEWS
U php/php-src/branches/PHP_5_3/ext/intl/dateformat/dateformat_parse.c
A php/php-src/branches/PHP_5_3/ext/intl/tests/bug50590.phpt
U php/php-src/branches/PHP_5_3/ext/intl/tests/dateformat_format_parse.phpt
U
php/php-src/branches/PHP_5_3/ext/intl/tests/dateformat_parse_timestamp_parsepos.phpt
U php/php-src/trunk/ext/intl/dateformat/dateformat_parse.c
A php/php-src/trunk/ext/intl/tests/bug50590.phpt
U php/php-src/trunk/ext/intl/tests/dateformat_format_parse.phpt
U
php/php-src/trunk/ext/intl/tests/dateformat_parse_timestamp_parsepos.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2010-09-01 18:27:41 UTC (rev 302981)
+++ php/php-src/branches/PHP_5_3/NEWS 2010-09-01 20:34:59 UTC (rev 302982)
@@ -64,6 +64,8 @@
- Fixed bug #51610 (Using oci_connect causes PHP to take a long time to
exit). Requires Oracle bug fix 9891199 for this patch to have an
effect. (Oracle Corp.)
+- Fixed bug #50590 (IntlDateFormatter::parse result is limited to the integer
+ range). (Stas)
- Fixed bug #50481 (Storing many SPLFixedArray in an array crashes). (Felipe)
22 Jul 2010, PHP 5.3.3
Modified: php/php-src/branches/PHP_5_3/ext/intl/dateformat/dateformat_parse.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/dateformat/dateformat_parse.c 2010-09-01 18:27:41 UTC (rev 302981)
+++ php/php-src/branches/PHP_5_3/ext/intl/dateformat/dateformat_parse.c 2010-09-01 20:34:59 UTC (rev 302982)
@@ -19,6 +19,7 @@
#endif
#include <unicode/ustring.h>
+#include <math.h>
#include "php_intl.h"
#include "intl_convert.h"
@@ -35,7 +36,7 @@
*/
static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* text_to_parse, int32_t text_len, int32_t *parse_pos, zval *return_value TSRMLS_DC)
{
- long result = 0;
+ double result = 0;
UDate timestamp =0;
UChar* text_utf16 = NULL;
int32_t text_utf16_len = 0;
@@ -52,12 +53,12 @@
INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" );
/* Since return is in sec. */
- result = (long )( timestamp / 1000 );
- if( result != (timestamp/1000) ) {
- intl_error_set( NULL, U_BUFFER_OVERFLOW_ERROR,
- "datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.\nThe valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.", 0 TSRMLS_CC );
+ result = (double)timestamp / U_MILLIS_PER_SECOND;
+ if(result > LONG_MAX || result < -LONG_MAX) {
+ ZVAL_DOUBLE(return_value, result<0?ceil(result):floor(result));
+ } else {
+ ZVAL_LONG(return_value, (long)result);
}
- RETURN_LONG( result );
}
/* }}} */
Added: php/php-src/branches/PHP_5_3/ext/intl/tests/bug50590.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/tests/bug50590.phpt (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/intl/tests/bug50590.phpt 2010-09-01 20:34:59 UTC (rev 302982)
@@ -0,0 +1,13 @@
+--TEST--
+Bug #50590 (IntlDateFormatter::parse result is limited to the integer range)
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+
+$fmt = new IntlDateFormatter("en_US", IntlDateFormatter::FULL, IntlDateFormatter::FULL);
+var_dump($fmt->parse("Wednesday, January 20, 2038 3:14:07 AM GMT"));
+
+?>
+--EXPECTF--
+float(2147570047)
Modified: php/php-src/branches/PHP_5_3/ext/intl/tests/dateformat_format_parse.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/tests/dateformat_format_parse.phpt 2010-09-01 18:27:41 UTC (rev 302981)
+++ php/php-src/branches/PHP_5_3/ext/intl/tests/dateformat_format_parse.phpt 2010-09-01 20:34:59 UTC (rev 302982)
@@ -187,16 +187,13 @@
IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
Formatted timestamp is : Monday, September 19, 2039 4:06:40 AM GMT+05:00
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : 2200000000
IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
Formatted timestamp is : September 19, 2039 4:06:40 AM GMT+05:00
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : 2200000000
IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
Formatted timestamp is : Sep 19, 2039 4:06:40 AM
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : 2200000000
------------
Input timestamp is : -2200000000
@@ -204,16 +201,13 @@
IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
Formatted timestamp is : Sunday, April 15, 1900 5:53:20 AM GMT+05:00
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : -2200000000
IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
Formatted timestamp is : April 15, 1900 5:53:20 AM GMT+05:00
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : -2200000000
IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
Formatted timestamp is : Apr 15, 1900 5:53:20 AM
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : -2200000000
------------
Input timestamp is : 90099999
@@ -297,4 +291,4 @@
Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
Formatted localtime_array is : Dec 17, 1895 12:13:11 AM
-Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
\ No newline at end of file
+Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
Modified: php/php-src/branches/PHP_5_3/ext/intl/tests/dateformat_parse_timestamp_parsepos.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/intl/tests/dateformat_parse_timestamp_parsepos.phpt 2010-09-01 18:27:41 UTC (rev 302981)
+++ php/php-src/branches/PHP_5_3/ext/intl/tests/dateformat_parse_timestamp_parsepos.phpt 2010-09-01 20:34:59 UTC (rev 302982)
@@ -76,8 +76,7 @@
Locale is : en_US_CA
------------
datetype = 0 ,timetype =0
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed text is : 33756908800
datetype = 1 ,timetype =1
Error while parsing as: 'Date parsing failed: U_PARSE_ERROR'
datetype = 2 ,timetype =2
@@ -117,8 +116,7 @@
datetype = 3 ,timetype =3
Error while parsing as: 'Date parsing failed: U_PARSE_ERROR'
datetype = -1 ,timetype =-1
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed text is : -2178601860
------------
Input text is : 19691218 08:49 AM
Modified: php/php-src/trunk/ext/intl/dateformat/dateformat_parse.c
===================================================================
--- php/php-src/trunk/ext/intl/dateformat/dateformat_parse.c 2010-09-01 18:27:41 UTC (rev 302981)
+++ php/php-src/trunk/ext/intl/dateformat/dateformat_parse.c 2010-09-01 20:34:59 UTC (rev 302982)
@@ -19,6 +19,7 @@
#endif
#include <unicode/ustring.h>
+#include <math.h>
#include "php_intl.h"
#include "intl_convert.h"
@@ -35,7 +36,7 @@
*/
static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* text_to_parse, int32_t text_len, int32_t *parse_pos, zval *return_value TSRMLS_DC)
{
- long result = 0;
+ double result = 0;
UDate timestamp =0;
UChar* text_utf16 = NULL;
int32_t text_utf16_len = 0;
@@ -52,12 +53,12 @@
INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" );
/* Since return is in sec. */
- result = (long )( timestamp / 1000 );
- if( result != (timestamp/1000) ) {
- intl_error_set( NULL, U_BUFFER_OVERFLOW_ERROR,
- "datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.\nThe valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.", 0 TSRMLS_CC );
+ result = (double)timestamp / U_MILLIS_PER_SECOND;
+ if(result > LONG_MAX || result < -LONG_MAX) {
+ ZVAL_DOUBLE(return_value, result<0?ceil(result):floor(result));
+ } else {
+ ZVAL_LONG(return_value, (long)result);
}
- RETURN_LONG( result );
}
/* }}} */
Added: php/php-src/trunk/ext/intl/tests/bug50590.phpt
===================================================================
--- php/php-src/trunk/ext/intl/tests/bug50590.phpt (rev 0)
+++ php/php-src/trunk/ext/intl/tests/bug50590.phpt 2010-09-01 20:34:59 UTC (rev 302982)
@@ -0,0 +1,13 @@
+--TEST--
+Bug #50590 (IntlDateFormatter::parse result is limited to the integer range)
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+
+$fmt = new IntlDateFormatter("en_US", IntlDateFormatter::FULL, IntlDateFormatter::FULL);
+var_dump($fmt->parse("Wednesday, January 20, 2038 3:14:07 AM GMT"));
+
+?>
+--EXPECTF--
+float(2147570047)
Modified: php/php-src/trunk/ext/intl/tests/dateformat_format_parse.phpt
===================================================================
--- php/php-src/trunk/ext/intl/tests/dateformat_format_parse.phpt 2010-09-01 18:27:41 UTC (rev 302981)
+++ php/php-src/trunk/ext/intl/tests/dateformat_format_parse.phpt 2010-09-01 20:34:59 UTC (rev 302982)
@@ -187,16 +187,13 @@
IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
Formatted timestamp is : Monday, September 19, 2039 4:06:40 AM GMT+05:00
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : 2200000000
IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
Formatted timestamp is : September 19, 2039 4:06:40 AM GMT+05:00
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : 2200000000
IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
Formatted timestamp is : Sep 19, 2039 4:06:40 AM
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : 2200000000
------------
Input timestamp is : -2200000000
@@ -204,16 +201,13 @@
IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
Formatted timestamp is : Sunday, April 15, 1900 5:53:20 AM GMT+05:00
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : -2200000000
IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
Formatted timestamp is : April 15, 1900 5:53:20 AM GMT+05:00
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : -2200000000
IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
Formatted timestamp is : Apr 15, 1900 5:53:20 AM
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed timestamp is : -2200000000
------------
Input timestamp is : 90099999
@@ -297,4 +291,4 @@
Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
Formatted localtime_array is : Dec 17, 1895 12:13:11 AM
-Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
\ No newline at end of file
+Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
Modified: php/php-src/trunk/ext/intl/tests/dateformat_parse_timestamp_parsepos.phpt
===================================================================
--- php/php-src/trunk/ext/intl/tests/dateformat_parse_timestamp_parsepos.phpt 2010-09-01 18:27:41 UTC (rev 302981)
+++ php/php-src/trunk/ext/intl/tests/dateformat_parse_timestamp_parsepos.phpt 2010-09-01 20:34:59 UTC (rev 302982)
@@ -76,8 +76,7 @@
Locale is : en_US_CA
------------
datetype = 0 ,timetype =0
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed text is : 33756908800
datetype = 1 ,timetype =1
Error while parsing as: 'Date parsing failed: U_PARSE_ERROR'
datetype = 2 ,timetype =2
@@ -117,8 +116,7 @@
datetype = 3 ,timetype =3
Error while parsing as: 'Date parsing failed: U_PARSE_ERROR'
datetype = -1 ,timetype =-1
-Error while parsing as: 'datefmt_parse: parsing of input parametrs resulted in value larger than data type long can handle.
-The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.: U_BUFFER_OVERFLOW_ERROR'
+Parsed text is : -2178601860
------------
Input text is : 19691218 08:49 AM
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php