From 03ecd79fe0bbe12984054f6d13da8ff248560cd5 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 20 Apr 2014 23:18:17 +0200 Subject: [PATCH] fix receiving utf-8 characters in multimedia push messages Throw AssertionError instead of logging and trying to recover --- .../securesms/mms/IncomingMediaMessage.java | 4 +++- src/org/thoughtcrime/securesms/util/Util.java | 15 ++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java b/src/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java index 18a856cfe2..fd269cf1d9 100644 --- a/src/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java +++ b/src/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java @@ -9,6 +9,7 @@ import org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent; import org.whispersystems.textsecure.util.Base64; import org.whispersystems.textsecure.util.Hex; +import ws.com.google.android.mms.pdu.CharacterSets; import ws.com.google.android.mms.pdu.EncodedStringValue; import ws.com.google.android.mms.pdu.PduBody; import ws.com.google.android.mms.pdu.PduHeaders; @@ -50,8 +51,9 @@ public class IncomingMediaMessage { if (!org.whispersystems.textsecure.util.Util.isEmpty(messageContent.getBody())) { PduPart text = new PduPart(); - text.setData(Util.toIsoBytes(messageContent.getBody())); + text.setData(Util.toUtf8Bytes(messageContent.getBody())); text.setContentType(Util.toIsoBytes("text/plain")); + text.setCharset(CharacterSets.UTF_8); body.addPart(text); } diff --git a/src/org/thoughtcrime/securesms/util/Util.java b/src/org/thoughtcrime/securesms/util/Util.java index 86e49add6c..61644935e0 100644 --- a/src/org/thoughtcrime/securesms/util/Util.java +++ b/src/org/thoughtcrime/securesms/util/Util.java @@ -98,9 +98,7 @@ public class Util { try { return new String(bytes, CharacterSets.MIMENAME_ISO_8859_1); } catch (UnsupportedEncodingException e) { - // Impossible to reach here! - Log.e("MmsDatabase", "ISO_8859_1 must be supported!", e); - return ""; + throw new AssertionError("ISO_8859_1 must be supported!"); } } @@ -108,8 +106,15 @@ public class Util { try { return isoString.getBytes(CharacterSets.MIMENAME_ISO_8859_1); } catch (UnsupportedEncodingException e) { - Log.w("Util", "ISO_8859_1 must be supported!", e); - return new byte[0]; + throw new AssertionError("ISO_8859_1 must be supported!"); + } + } + + public static byte[] toUtf8Bytes(String utf8String) { + try { + return utf8String.getBytes(CharacterSets.MIMENAME_UTF_8); + } catch (UnsupportedEncodingException e) { + throw new AssertionError("UTF_8 must be supported!"); } }