From 72299bf0d240072174f847d13f1c9498b3ef9fa6 Mon Sep 17 00:00:00 2001 From: Cylen Yao Date: Wed, 4 Jun 2014 19:11:27 +0800 Subject: [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) --- libutils/Unicode.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libutils/Unicode.cpp') diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp index a66e3bbbb..1ee1a0b57 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; -- cgit v1.2.3