summaryrefslogtreecommitdiffstats
path: root/libutils/Unicode.cpp
diff options
context:
space:
mode:
authorCylen Yao <cylen.yao@mediatek.com>2014-06-04 19:11:27 +0800
committerRaph Levien <raph@google.com>2014-06-10 19:14:59 +0000
commit72299bf0d240072174f847d13f1c9498b3ef9fa6 (patch)
treef8dfb16fb9a8602cee9da7a7c5771d25e335a533 /libutils/Unicode.cpp
parentc24b98c7d8d9380f885bb6ea4055a34082353879 (diff)
downloadsystem_core-72299bf0d240072174f847d13f1c9498b3ef9fa6.zip
system_core-72299bf0d240072174f847d13f1c9498b3ef9fa6.tar.gz
system_core-72299bf0d240072174f847d13f1c9498b3ef9fa6.tar.bz2
[Bug]NE when playing mp3 with incorrect UTF16 char
Bug: 15274351 Bug: 15539240 Many MP3 files have incorrect utf16 chars, but the Utf16_to_utf8_length() routine checks for errors in standard utf16 char. utf16_to_utf8() was not checking for errors in standard utf16 char. Change-Id: Iafd922ff92cabe6bba8971215fcfd1fd471c894b (cherry picked from commit 605b139cdf56364c6c9b37e59dd12efc61c24631)
Diffstat (limited to 'libutils/Unicode.cpp')
-rw-r--r--libutils/Unicode.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp
index a66e3bb..1ee1a0b 100644
--- a/libutils/Unicode.cpp
+++ b/libutils/Unicode.cpp
@@ -342,7 +342,8 @@ void utf16_to_utf8(const char16_t* src, size_t src_len, char* dst)
while (cur_utf16 < end_utf16) {
char32_t utf32;
// surrogate pairs
- if ((*cur_utf16 & 0xFC00) == 0xD800) {
+ if((*cur_utf16 & 0xFC00) == 0xD800 && (cur_utf16 + 1) < end_utf16
+ && (*(cur_utf16 + 1) & 0xFC00) == 0xDC00) {
utf32 = (*cur_utf16++ - 0xD800) << 10;
utf32 |= *cur_utf16++ - 0xDC00;
utf32 += 0x10000;