Skip to content

Commit

Permalink
Merge branch 'PHP-5.4' of https://git.php.net/repository/php-src into…
Browse files Browse the repository at this point in the history
… PHP-5.4

* 'PHP-5.4' of https://git.php.net/repository/php-src:
  Improved fix for bug #44686 (SOAP-ERROR: Parsing WSDL)
  Fixed bug #65018 (SoapHeader problems with SoapServer)
  MFH: fixed #65045: mb_convert_encoding breaks well-formed character.
  • Loading branch information
cjbj committed Jul 31, 2013
2 parents 1d7b697 + 4395f70 commit 4590070
Show file tree
Hide file tree
Showing 9 changed files with 350 additions and 245 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ PHP NEWS
. Fixed bug #50308 (session id not appended properly for empty anchor tags).
(Arpad)

- SOAP:
. Fixed bug #65018 (SoapHeader problems with SoapServer). (Dmitry)

- SPL:
. Fixed bug #65328 (Segfault when getting SplStack object Value). (Laruence)

Expand Down
184 changes: 94 additions & 90 deletions ext/mbstring/libmbfl/filters/mbfilter_utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const struct mbfl_convert_vtbl vtbl_utf8_wchar = {
mbfl_filt_conv_common_ctor,
mbfl_filt_conv_common_dtor,
mbfl_filt_conv_utf8_wchar,
mbfl_filt_conv_common_flush
mbfl_filt_conv_utf8_wchar_flush
};

const struct mbfl_convert_vtbl vtbl_wchar_utf8 = {
Expand All @@ -93,118 +93,122 @@ const struct mbfl_convert_vtbl vtbl_wchar_utf8 = {

#define CK(statement) do { if ((statement) < 0) return (-1); } while (0)

int mbfl_filt_put_invalid_char(int c, mbfl_convert_filter *filter)
{
int w;
w = c & MBFL_WCSGROUP_MASK;
w |= MBFL_WCSGROUP_THROUGH;
filter->status = 0;
filter->cache = 0;
CK((*filter->output_function)(w, filter->data));
}


/*
* UTF-8 => wchar
*/
int mbfl_filt_conv_utf8_wchar(int c, mbfl_convert_filter *filter)
{
int s, c1, w = 0, flag = 0;

if (c < 0x80) {
if (filter->status != 0) {
w = (filter->cache & MBFL_WCSGROUP_MASK) | MBFL_WCSGROUP_THROUGH;
CK((*filter->output_function)(w, filter->data));
filter->status = 0;
filter->cache = 0;
}
if (c >= 0) {
retry:
switch (filter->status & 0xff) {
case 0x00:
if (c < 0x80) {
CK((*filter->output_function)(c, filter->data));
} else if (c >= 0xc2 && c <= 0xdf) { /* 2byte code first char: 0xc2-0xdf */
filter->status = 0x10;
filter->cache = c & 0x1f;
} else if (c >= 0xe0 && c <= 0xef) { /* 3byte code first char: 0xe0-0xef */
filter->status = 0x20;
filter->cache = c & 0xf;
} else if (c >= 0xf0 && c <= 0xf4) { /* 3byte code first char: 0xf0-0xf4 */
filter->status = 0x30;
filter->cache = c & 0x7;
} else {
mbfl_filt_put_invalid_char(c, filter);
}
} else if (c < 0xc0) {
int status = filter->status & 0xff;
switch (status) {
case 0x10: /* 2byte code 2nd char: 0x80-0xbf */
case 0x21: /* 3byte code 3rd char: 0x80-0xbf */
case 0x32: /* 4byte code 4th char: 0x80-0xbf */
filter->status = 0;
s = filter->cache | (c & 0x3f);
break;
case 0x10: /* 2byte code 2nd char: 0x80-0xbf */
case 0x21: /* 3byte code 3rd char: 0x80-0xbf */
case 0x32: /* 4byte code 4th char: 0x80-0xbf */
filter->status = 0;
if (c >= 0x80 && c <= 0xbf) {
s = (filter->cache<<6) | (c & 0x3f);
filter->cache = 0;
if ((status == 0x10 && s >= 0x80) ||
(status == 0x21 && s >= 0x800 && (s < 0xd800 || s > 0xdfff)) ||
(status == 0x32 && s >= 0x10000 && s < 0x110000)) {
CK((*filter->output_function)(s, filter->data));
} else {
w = s & MBFL_WCSGROUP_MASK;
flag = 1;
}
break;
case 0x20: /* 3byte code 2nd char: 0:0xa0-0xbf,D:0x80-9F,1-C,E-F:0x80-0x9f */
s = filter->cache | ((c & 0x3f) << 6);
c1 = (s >> 12) & 0xf;
if ((c1 == 0x0 && c >= 0xa0) ||
(c1 == 0xd && c < 0xa0) ||
(c1 > 0x0 && c1 != 0xd)) {
filter->cache = s;
filter->status++;
} else {
w = s & MBFL_WCSGROUP_MASK;
flag = 1;
}
break;
case 0x31: /* 4byte code 3rd char: 0x80-0xbf */
filter->cache |= ((c & 0x3f) << 6);
filter->status++;
break;
case 0x30: /* 4byte code 2nd char: 0:0x90-0xbf,1-3:0x80-0xbf,4:0x80-0x8f */
s = filter->cache | ((c & 0x3f) << 12);
c1 = (s >> 18) & 0x7;
if ((c1 == 0x0 && c >= 0x90) ||
(c1 > 0x0 && c1 < 0x4) ||
(c1 == 0x4 && c < 0x90)) {
filter->cache = s;
filter->status++;
} else {
w = s & MBFL_WCSGROUP_MASK;
flag = 1;
}
break;
default:
w = c & MBFL_WCSGROUP_MASK;
flag = 1;
break;
CK((*filter->output_function)(s, filter->data));
} else {
mbfl_filt_put_invalid_char(filter->cache, filter);
goto retry;
}
} else if (c < 0xc2) { /* invalid: 0xc0,0xc1 */
w = c & MBFL_WCSGROUP_MASK;
flag = 1;
} else if (c < 0xe0) { /* 2byte code first char: 0xc2-0xdf */
if (filter->status == 0x0) {
filter->status = 0x10;
filter->cache = (c & 0x1f) << 6;
break;
case 0x20: /* 3byte code 2nd char: 0:0xa0-0xbf,D:0x80-9F,1-C,E-F:0x80-0x9f */
s = (filter->cache<<6) | (c & 0x3f);
c1 = filter->cache & 0xf;

if ((c >= 0x80 && c <= 0xbf) &&
((c1 == 0x0 && c >= 0xa0) ||
(c1 == 0xd && c < 0xa0) ||
(c1 > 0x0 && c1 != 0xd))) {
filter->cache = s;
filter->status++;
} else {
w = c & MBFL_WCSGROUP_MASK;
flag = 1;
mbfl_filt_put_invalid_char(filter->cache, filter);
goto retry;
}
} else if (c < 0xf0) { /* 3byte code first char: 0xe0-0xef */
if (filter->status == 0x0) {
filter->status = 0x20;
filter->cache = (c & 0xf) << 12;
break;
case 0x30: /* 4byte code 2nd char: 0:0x90-0xbf,1-3:0x80-0xbf,4:0x80-0x8f */
s = (filter->cache<<6) | (c & 0x3f);
c1 = filter->cache & 0x7;

if ((c >= 0x80 && c <= 0xbf) &&
((c1 == 0x0 && c >= 0x90) ||
(c1 == 0x4 && c < 0x90) ||
(c1 > 0x0 && c1 != 0x4))) {
filter->cache = s;
filter->status++;
} else {
w = c & MBFL_WCSGROUP_MASK;
flag = 1;
mbfl_filt_put_invalid_char(filter->cache, filter);
goto retry;
}
} else if (c < 0xf5) { /* 4byte code first char: 0xf0-0xf4 */
if (filter->status == 0x0) {
filter->status = 0x30;
filter->cache = (c & 0x7) << 18;
break;
case 0x31: /* 4byte code 3rd char: 0x80-0xbf */
if (c >= 0x80 && c <= 0xbf) {
filter->cache = (filter->cache<<6) | (c & 0x3f);
filter->status++;
} else {
w = c & MBFL_WCSGROUP_MASK;
flag = 1;
mbfl_filt_put_invalid_char(filter->cache, filter);
goto retry;
}
} else {
w = c & MBFL_WCSGROUP_MASK;
flag = 1;
}

if (flag) {
w |= MBFL_WCSGROUP_THROUGH;
CK((*filter->output_function)(w, filter->data));
break;
default:
filter->status = 0;
filter->cache = 0;
break;
}

return c;
}

int mbfl_filt_conv_utf8_wchar_flush(mbfl_convert_filter *filter)
{
int status, cache;

status = filter->status;
cache = filter->cache;

filter->status = 0;
filter->cache = 0;

if (status != 0) {
mbfl_filt_put_invalid_char(cache, filter);
}

if (filter->flush_function != NULL) {
(*filter->flush_function)(filter->data);
}
return 0;
}

/*
* wchar => UTF-8
*/
Expand Down
1 change: 1 addition & 0 deletions ext/mbstring/libmbfl/filters/mbfilter_utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ extern const struct mbfl_convert_vtbl vtbl_wchar_utf8;

int mbfl_filt_conv_utf8_wchar(int c, mbfl_convert_filter *filter);
int mbfl_filt_conv_wchar_utf8(int c, mbfl_convert_filter *filter);
int mbfl_filt_conv_utf8_wchar_flush(mbfl_convert_filter *filter);

#endif /* MBFL_MBFILTER_UTF8_H */
Loading

0 comments on commit 4590070

Please sign in to comment.