com php-src: partial revamp ext/intl: ext/intl/collator/collato r_compare.c ext/intl/collator/collator_is_numeric.c ext/intl/intl_convert.c
ext/intl/intl_convertcpp.c pp
| From: | Anatol Belski | Date: | Fri, 17 Jan 2014 22:52:19 +0000 |
| Subject: | com php-src: partial revamp ext/intl: ext/intl/collator/collato r_compare.c ext/intl/collator/collator_is_numeric.c ext/intl/intl_convert.c ext/intl/intl_convertcpp.c pp |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-75681@lists.php.net to get a copy of this message | ||
Commit: f5d48e852465aa4a89710b2f491b73622ad6d789
Author: Anatol Belski <ab@php.net> Fri, 17 Jan 2014 23:52:19 +0100
Parents: ee039d5a1a2b132f6288e7794430e57911573a61
Branches: str_size_and_int64
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f5d48e852465aa4a89710b2f491b73622ad6d789
Log:
partial revamp ext/intl
Changed paths:
M ext/intl/collator/collator_compare.c
M ext/intl/collator/collator_is_numeric.c
M ext/intl/intl_convert.c
M ext/intl/intl_convertcpp.cpp
Diff:
diff --git a/ext/intl/collator/collator_compare.c b/ext/intl/collator/collator_compare.c
index 0398ab6..1370927 100644
--- a/ext/intl/collator/collator_compare.c
+++ b/ext/intl/collator/collator_compare.c
@@ -55,6 +55,16 @@ PHP_FUNCTION( collator_compare )
RETURN_FALSE;
}
+ if (str1_len > INT32_MAX) {
+ php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "The first string to compare is too
long");
+
+ RETURN_FALSE;
+ } else if (str1_len > INT32_MAX) {
+ php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "The second string to compare is too
long");
+
+ RETURN_FALSE;
+ }
+
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
@@ -110,8 +120,8 @@ PHP_FUNCTION( collator_compare )
/* Then compare them. */
result = ucol_strcoll(
co->ucoll,
- ustr1, ustr1_len,
- ustr2, ustr2_len );
+ ustr1, (int32_t)ustr1_len,
+ ustr2, (int32_t)ustr2_len );
if( ustr1 )
efree( ustr1 );
diff --git a/ext/intl/collator/collator_is_numeric.c b/ext/intl/collator/collator_is_numeric.c
index bfc843d..db1b89c 100644
--- a/ext/intl/collator/collator_is_numeric.c
+++ b/ext/intl/collator/collator_is_numeric.c
@@ -81,7 +81,7 @@ static double collator_u_strtod(const UChar *nptr, UChar **endptr) /* {{{ */
if (any) {
char buf[64], *numbuf, *bufpos;
- int length = u - nstart;
+ ptrdiff_t length = u - nstart;
double value;
if (length < sizeof(buf)) {
@@ -125,15 +125,15 @@ static double collator_u_strtod(const UChar *nptr, UChar **endptr) /* {{{ */
*
* Ignores `locale' stuff.
*/
-static long collator_u_strtol(nptr, endptr, base)
+static php_int_t collator_u_strtol(nptr, endptr, base)
const UChar *nptr;
UChar **endptr;
register int base;
{
register const UChar *s = nptr;
- register unsigned long acc;
+ register php_uint_t acc;
register UChar c;
- register unsigned long cutoff;
+ register php_uint_t cutoff;
register int neg = 0, any, cutlim;
if (s == NULL) {
@@ -184,9 +184,9 @@ static long collator_u_strtol(nptr, endptr, base)
* Set any if any `digits' consumed; make it negative to indicate
* overflow.
*/
- cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
- cutlim = cutoff % (unsigned long)base;
- cutoff /= (unsigned long)base;
+ cutoff = neg ? -(php_uint_t)PHP_INT_MIN : PHP_INT_MAX;
+ cutlim = cutoff % (php_uint_t)base;
+ cutoff /= (php_uint_t)base;
for (acc = 0, any = 0;; c = *s++) {
if (c >= 0x30 /*'0'*/ && c <= 0x39 /*'9'*/)
c -= 0x30 /*'0'*/;
@@ -208,7 +208,7 @@ static long collator_u_strtol(nptr, endptr, base)
}
}
if (any < 0) {
- acc = neg ? LONG_MIN : LONG_MAX;
+ acc = neg ? PHP_INT_MIN : PHP_INT_MAX;
errno = ERANGE;
} else if (neg)
acc = -acc;
diff --git a/ext/intl/intl_convert.c b/ext/intl/intl_convert.c
index da88998..a3d93af 100644
--- a/ext/intl/intl_convert.c
+++ b/ext/intl/intl_convert.c
@@ -51,13 +51,19 @@ void intl_convert_utf8_to_utf16(
UChar* dst_buf = NULL;
int32_t dst_len = 0;
+ if (src_len > INT32_MAX) {
+ *target = NULL;
+ *target_len = 0;
+ return;
+ }
+
/* If *target is NULL determine required destination buffer size (pre-flighting).
* Otherwise, attempt to convert source string; if *target buffer is not large enough
* it will be resized appropriately.
*/
*status = U_ZERO_ERROR;
- u_strFromUTF8( *target, *target_len, &dst_len, src, src_len, status );
+ u_strFromUTF8( *target, (int32_t)*target_len, &dst_len, src, (int32_t)src_len, status );
if( *status == U_ZERO_ERROR )
{
@@ -79,7 +85,7 @@ void intl_convert_utf8_to_utf16(
/* Convert source string from UTF-8 to UTF-16. */
*status = U_ZERO_ERROR;
- u_strFromUTF8( dst_buf, dst_len+1, NULL, src, src_len, status );
+ u_strFromUTF8( dst_buf, dst_len+1, NULL, src, (int32_t)src_len, status );
if( U_FAILURE( *status ) )
{
efree( dst_buf );
@@ -115,9 +121,15 @@ void intl_convert_utf16_to_utf8(
char* dst_buf = NULL;
int32_t dst_len;
+ if ((php_int_t)src_len > INT32_MAX || (php_int_t)src_len < INT32_MIN) {
+ target = NULL;
+ target_len = 0;
+ return;
+ }
+
/* Determine required destination buffer size (pre-flighting). */
*status = U_ZERO_ERROR;
- u_strToUTF8( NULL, 0, &dst_len, src, src_len, status );
+ u_strToUTF8( NULL, 0, &dst_len, src, (int32_t)src_len, status );
/* Bail out if an unexpected error occurred.
* (U_BUFFER_OVERFLOW_ERROR means that *target buffer is not large enough).
@@ -131,7 +143,7 @@ void intl_convert_utf16_to_utf8(
/* Convert source string from UTF-8 to UTF-16. */
*status = U_ZERO_ERROR;
- u_strToUTF8( dst_buf, dst_len, NULL, src, src_len, status );
+ u_strToUTF8( dst_buf, dst_len, NULL, src, (int32_t)src_len, status );
if( U_FAILURE( *status ) )
{
efree( dst_buf );
diff --git a/ext/intl/intl_convertcpp.cpp b/ext/intl/intl_convertcpp.cpp
index f904e8a..fee00df 100644
--- a/ext/intl/intl_convertcpp.cpp
+++ b/ext/intl/intl_convertcpp.cpp
@@ -29,14 +29,22 @@ int intl_stringFromChar(UnicodeString &ret, char *str, php_size_t str_len,
UErro
{
//the number of UTF-16 code units is not larger than that of UTF-8 code
//units, + 1 for the terminator
- int32_t capacity = str_len + 1;
+ int32_t capacity;
//no check necessary -- if NULL will fail ahead
- UChar *utf16 = ret.getBuffer(capacity);
+ UChar *utf16;
int32_t utf16_len = 0;
+
+ if (str_len > INT32_MAX) {
+ return FAILURE;
+ }
+
+ capacity = (int32_t)(str_len + 1);
+ utf16 = ret.getBuffer(capacity);
+
*status = U_ZERO_ERROR;
u_strFromUTF8WithSub(utf16, ret.getCapacity(), &utf16_len,
- str, str_len, U_SENTINEL /* no substitution */, NULL,
+ str, (int32_t)str_len, U_SENTINEL /* no substitution */, NULL,
status);
ret.releaseBuffer(utf16_len);
if (U_FAILURE(*status)) {