Add bound checks to utf16_to_utf8

Bug: 29250543
Change-Id: I518e7b2fe10aaa3f1c1987586a09b1110aff7e1a
(cherry picked from commit 7e93b2ddcb49b5365fbe1dab134ffb38e6f1c719)

status_t Parcel::writeUtf8AsUtf16(const std::string& str) {
 const uint8_t* strData = (uint8_t*)str.data();
 const size_t strLen= str.length();
 const ssize_t utf16Len = utf8_to_utf16_length(strData, strLen);
 if (utf16Len < 0 || utf16Len> std::numeric_limits<int32_t>::max()) {
 return BAD_VALUE;
 }

 status_t err = writeInt32(utf16Len);
 if (err) {
 return err;
 }

 void* dst = writeInplace((utf16Len + 1) * sizeof(char16_t));
 if (!dst) {
 return NO_MEMORY;
 }

    utf8_to_utf16(strData, strLen, (char16_t*)dst);

 return NO_ERROR;
}

status_t Parcel::writeUtf8AsUtf16(const std::string& str) {
 const uint8_t* strData = (uint8_t*)str.data();
 const size_t strLen= str.length();
 const ssize_t utf16Len = utf8_to_utf16_length(strData, strLen);
 if (utf16Len < 0 || utf16Len> std::numeric_limits<int32_t>::max()) {
 return BAD_VALUE;
 }

 status_t err = writeInt32(utf16Len);
 if (err) {
 return err;
 }

 void* dst = writeInplace((utf16Len + 1) * sizeof(char16_t));
 if (!dst) {
 return NO_MEMORY;
 }

    utf8_to_utf16(strData, strLen, (char16_t*)dst);

 return NO_ERROR;
}
