com php-src: Merge branch 'PHP-7.2': ext/mbstring/mbstring.c

From: Date: Thu, 03 Aug 2017 19:17:26 +0000
Subject: com php-src: Merge branch 'PHP-7.2': ext/mbstring/mbstring.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-98935@lists.php.net to get a copy of this message
Commit: 3d948d77d112684781fd81e7124350d3a32e5245 Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 3 Aug 2017 21:17:26 +0200 Parents: 25b41c61d21b1f1260c2774f6a347208f269cfeb a8a9e93e9a902ffd4099e3ba2a7a269da09120c5 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3d948d77d112684781fd81e7124350d3a32e5245 Log: Merge branch 'PHP-7.2' Changed paths: MM ext/mbstring/mbstring.c Diff: diff --cc ext/mbstring/mbstring.c index 3689e5f,732b5f6..584523e --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@@ -2021,71 -1976,23 +2021,23 @@@ PHP_FUNCTION(mb_detect_order } /* }}} */ -static inline int php_mb_check_code_point(long cp) +static inline int php_mb_check_code_point(zend_long cp) { - enum mbfl_no_encoding no_enc; - char* buf; - char buf_len; - - no_enc = MBSTRG(current_internal_encoding)->no_encoding; - - if (php_mb_is_no_encoding_utf8(no_enc)) { - - if ((cp > 0 && 0xd800 > cp) || (cp > 0xdfff && 0x110000 > cp)) { - return 1; - } - + if (cp <= 0 || cp >= 0x110000) { + /* Out of Unicode range */ return 0; - } else if (php_mb_is_no_encoding_unicode(no_enc)) { - - if (0 > cp || cp > 0x10ffff) { - return 0; - } - - return 1; - - // backward compatibility - } else if (php_mb_is_unsupported_no_encoding(no_enc)) { - return cp < 0xffff && cp > 0x0; - } - - if (cp < 0x100) { - buf_len = 1; - buf = (char *) safe_emalloc(buf_len, 1, 1); - buf[0] = cp; - buf[1] = 0; - } else if (cp < 0x10000) { - buf_len = 2; - buf = (char *) safe_emalloc(buf_len, 1, 1); - buf[0] = cp >> 8; - buf[1] = cp & 0xff; - buf[2] = 0; - } else if (cp < 0x1000000) { - buf_len = 3; - buf = (char *) safe_emalloc(buf_len, 1, 1); - buf[0] = cp >> 16; - buf[1] = (cp >> 8) & 0xff; - buf[2] = cp & 0xff; - buf[3] = 0; - } else { - buf_len = 4; - buf = (char *) safe_emalloc(buf_len, 1, 1); - buf[0] = cp >> 24; - buf[1] = (cp >> 16) & 0xff; - buf[2] = (cp >> 8) & 0xff; - buf[3] = cp & 0xff; - buf[4] = 0; } - if (php_mb_check_encoding(buf, buf_len, NULL)) { - efree(buf); - - return 1; + if (cp >= 0xd800 && cp <= 0xdfff) { + /* Surrogate code-point. These are never valid on their own and we only allow a single + * substitute character. */ + return 0; } - efree(buf); - - return 0; + /* As the we do not know the target encoding of the conversion operation that is going to + * use the substitution character, we cannot check whether the codepoint is actually mapped + * in the given encoding at this point. Thus we have to accept everything. */ + return 1; } /* {{{ proto mixed mb_substitute_character([mixed substchar])

« previous php.cvs (#98935) next »