From: Moriyoshi Koizumi Date: Fri, 11 Sep 2009 08:22:19 +0000 (+0000) Subject: - Fix bug #49528 (UTF-16 strings prefixed by BOM wrongly converted). X-Git-Tag: php-5.4.0alpha1~191^2~2667 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=384c7bce5a0c91109a50e3ae614759800fc658e9;p=php - Fix bug #49528 (UTF-16 strings prefixed by BOM wrongly converted). --- diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf16.c b/ext/mbstring/libmbfl/filters/mbfilter_utf16.c index b6c2aeda5b..5df6551d4d 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf16.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf16.c @@ -127,7 +127,7 @@ int mbfl_filt_conv_utf16_wchar(int c, mbfl_convert_filter *filter) int n, endian; endian = filter->status & 0xff00; - switch (filter->status & 0xff) { + switch (filter->status & 0x0f) { case 0: if (endian) { n = c & 0xff; @@ -144,15 +144,8 @@ int mbfl_filt_conv_utf16_wchar(int c, mbfl_convert_filter *filter) n = c & 0xff; } n |= filter->cache & 0xffff; - filter->status &= ~0xff; - if (n == 0xfffe) { - if (endian) { - filter->status = 0; /* big-endian */ - } else { - filter->status = 0x100; /* little-endian */ - } - CK((*filter->output_function)(0xfeff, filter->data)); - } else if (n >= 0xd800 && n < 0xdc00) { + filter->status &= ~0x0f; + if (n >= 0xd800 && n < 0xdc00) { filter->cache = ((n & 0x3ff) << 16) + 0x400000; } else if (n >= 0xdc00 && n < 0xe000) { n &= 0x3ff; @@ -166,7 +159,21 @@ int mbfl_filt_conv_utf16_wchar(int c, mbfl_convert_filter *filter) CK((*filter->output_function)(n, filter->data)); } } else { + int is_first = filter->status & 0x10; filter->cache = 0; + filter->status |= 0x10; + if (!is_first) { + if (n == 0xfffe) { + if (endian) { + filter->status &= ~0x100; /* big-endian */ + } else { + filter->status |= 0x100; /* little-endian */ + } + break; + } else if (n == 0xfeff) { + break; + } + } CK((*filter->output_function)(n, filter->data)); } break; diff --git a/ext/mbstring/tests/bug49528.phpt b/ext/mbstring/tests/bug49528.phpt new file mode 100644 index 0000000000..b06c35f85e --- /dev/null +++ b/ext/mbstring/tests/bug49528.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #49528 (UTF-16 strings prefixed by BOM wrongly converted) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +string(8) "02010403" +string(8) "01020304" +string(12) "feff02010403" +string(12) "fffe02010403" +string(12) "fffe01020304" +string(12) "feff01020304"