This commit is contained in:
Rasmus Lerdorf 2008-01-29 23:29:04 +00:00
parent 65c4bd9d08
commit b5ff09a345
2 changed files with 28 additions and 3 deletions

View File

@ -0,0 +1,13 @@
--TEST--
Bug #43957 - utf8_decode() bogus conversion on multibyte indicator near end of string
--SKIPIF--
<?php
require_once("skipif.inc");
if (!extension_loaded('xml')) die ("skip xml extension not available");
?>
--FILE--
<?php
echo utf8_decode('abc'.chr(0xe0));
?>
--EXPECTF--
abc?

View File

@ -591,15 +591,27 @@ PHPAPI char *xml_utf8_decode(const XML_Char *s, int len, int *newlen, const XML_
while (pos > 0) {
c = (unsigned char)(*s);
if (c >= 0xf0) { /* four bytes encoded, 21 bits */
c = ((s[0]&7)<<18) | ((s[1]&63)<<12) | ((s[2]&63)<<6) | (s[3]&63);
if(pos-4 >= 0) {
c = ((s[0]&7)<<18) | ((s[1]&63)<<12) | ((s[2]&63)<<6) | (s[3]&63);
} else {
c = '?';
}
s += 4;
pos -= 4;
} else if (c >= 0xe0) { /* three bytes encoded, 16 bits */
c = ((s[0]&63)<<12) | ((s[1]&63)<<6) | (s[2]&63);
if(pos-3 >= 0) {
c = ((s[0]&63)<<12) | ((s[1]&63)<<6) | (s[2]&63);
} else {
c = '?';
}
s += 3;
pos -= 3;
} else if (c >= 0xc0) { /* two bytes encoded, 11 bits */
c = ((s[0]&63)<<6) | (s[1]&63);
if(pos-3 >= 0) {
c = ((s[0]&63)<<6) | (s[1]&63);
} else {
c = '?';
}
s += 2;
pos -= 2;
} else {