From: Anatol Belski Date: Thu, 28 Aug 2014 19:59:00 +0000 (+0200) Subject: fixed trim() and strtok() to work with big strings X-Git-Tag: PRE_PHP7_REMOVALS~212 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=898e1570a2f1051d40045545e3bd3640247799fa;p=php fixed trim() and strtok() to work with big strings --- diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index d3d01797d7..57e68a2d53 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -759,11 +759,14 @@ static inline void zend_assign_to_object(zval *retval, zval *object_ptr, zval *p static void zend_assign_to_string_offset(zval *str_offset, zval *value, int value_type, zval *result TSRMLS_DC) { zval *str = Z_STR_OFFSET_STR_P(str_offset); - uint32_t offset = Z_STR_OFFSET_IDX_P(str_offset); + /* XXX String offset is uint32_t in _zval_struct, so can address only 2^32+1 space. + To make the offset get over that barier, we need to make str_offset size_t and that + would grow zval size by 8 bytes (currently from 16 to 24) on 64 bit build. */ + size_t offset = (size_t)Z_STR_OFFSET_IDX_P(str_offset); zend_string *old_str; - if ((int)offset < 0) { - zend_error(E_WARNING, "Illegal string offset: %d", offset); + if ((zend_long)offset < 0) { + zend_error(E_WARNING, "Illegal string offset: %zd", offset); zend_string_release(Z_STR_P(str)); if (result) { ZVAL_NULL(result); @@ -773,7 +776,7 @@ static void zend_assign_to_string_offset(zval *str_offset, zval *value, int valu old_str = Z_STR_P(str); if (offset >= Z_STRLEN_P(str)) { - int old_len = Z_STRLEN_P(str); + size_t old_len = Z_STRLEN_P(str); Z_STR_P(str) = zend_string_realloc(Z_STR_P(str), offset + 1, 0); Z_TYPE_INFO_P(str) = IS_STRING_EX; memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len); diff --git a/ext/standard/string.c b/ext/standard/string.c index a37b858b2f..a85a73fe6a 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -781,7 +781,7 @@ static inline int php_charmask(unsigned char *input, size_t len, char *mask TSRM PHPAPI char *php_trim(char *c, size_t len, char *what, size_t what_len, zval *return_value, int mode TSRMLS_DC) { register zend_long i; - int trimmed = 0; + size_t trimmed = 0; char mask[256]; if (what) { @@ -1257,7 +1257,7 @@ PHP_FUNCTION(strtok) char *token_end; char *p; char *pe; - int skipped = 0; + size_t skipped = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|S", &str, &tok) == FAILURE) { return; @@ -1465,7 +1465,7 @@ quit_loop: if (state == 1) { cend = c; } - if (suffix != NULL && sufflen < (uint)(cend - comp) && + if (suffix != NULL && sufflen < (size_t)(cend - comp) && memcmp(cend - sufflen, suffix, sufflen) == 0) { cend -= sufflen; } @@ -1554,7 +1554,7 @@ PHP_FUNCTION(pathinfo) if ((opt & PHP_PATHINFO_EXTENSION) == PHP_PATHINFO_EXTENSION) { const char *p; - int idx; + ptrdiff_t idx; if (!have_basename) { ret = php_basename(path, path_len, NULL, 0 TSRMLS_CC); @@ -1570,7 +1570,7 @@ PHP_FUNCTION(pathinfo) if ((opt & PHP_PATHINFO_FILENAME) == PHP_PATHINFO_FILENAME) { const char *p; - int idx; + ptrdiff_t idx; /* Have we already looked up the basename? */ if (!have_basename && !ret) {