Skip to content

Commit 7e53511

Browse files
committed
Make ext/soap work around libxml2 bug in xmlCheckUTF8 (2.6.7-2.6.13)
1 parent 882a4c4 commit 7e53511

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

ext/soap/php_encoding.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,32 @@ static zval *to_zval_stringb(encodeTypePtr type, xmlNodePtr data)
581581
return ret;
582582
}
583583

584+
static int php_soap_xmlCheckUTF8(const unsigned char *s)
585+
{
586+
int i;
587+
unsigned char c;
588+
589+
for (i = 0; (c = s[i++]);) {
590+
if ((c & 0x80) == 0) {
591+
} else if ((c & 0xe0) == 0xc0) {
592+
if ((s[i++] & 0xc0) != 0x80) {
593+
return 0;
594+
}
595+
} else if ((c & 0xf0) == 0xe0) {
596+
if ((s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80) {
597+
return 0;
598+
}
599+
} else if ((c & 0xf8) == 0xf0) {
600+
if ((s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80) {
601+
return 0;
602+
}
603+
} else {
604+
return 0;
605+
}
606+
}
607+
return 1;
608+
}
609+
584610
static xmlNodePtr to_xml_string(encodeTypePtr type, zval *data, int style, xmlNodePtr parent)
585611
{
586612
xmlNodePtr ret;
@@ -612,12 +638,12 @@ static xmlNodePtr to_xml_string(encodeTypePtr type, zval *data, int style, xmlNo
612638
efree(str);
613639
str = estrdup(xmlBufferContent(out));
614640
new_len = n;
615-
} else if (!xmlCheckUTF8(str)) {
641+
} else if (!php_soap_xmlCheckUTF8(str)) {
616642
soap_error1(E_ERROR, "Encoding: string '%s' is not a valid utf-8 string", str);
617643
}
618644
xmlBufferFree(out);
619645
xmlBufferFree(in);
620-
} else if (!xmlCheckUTF8(str)) {
646+
} else if (!php_soap_xmlCheckUTF8(str)) {
621647
soap_error1(E_ERROR, "Encoding: string '%s' is not a valid utf-8 string", str);
622648
}
623649

0 commit comments

Comments
 (0)