From bcecc30d331378244627b679e193d6767fcbfeca Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 15 Oct 2019 23:10:15 -0400 Subject: [PATCH] Disallow RecipientId's of zero. --- .../thoughtcrime/securesms/database/MmsDatabase.java | 12 ++++++------ .../securesms/recipients/RecipientId.java | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/MmsDatabase.java b/src/org/thoughtcrime/securesms/database/MmsDatabase.java index 469cf43347..713655ab3c 100644 --- a/src/org/thoughtcrime/securesms/database/MmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/MmsDatabase.java @@ -623,7 +623,7 @@ public class MmsDatabase extends MessagingDatabase { String networkDocument = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.NETWORK_FAILURE)); long quoteId = cursor.getLong(cursor.getColumnIndexOrThrow(QUOTE_ID)); - RecipientId quoteAuthor = RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(QUOTE_AUTHOR))); + long quoteAuthor = cursor.getLong(cursor.getColumnIndexOrThrow(QUOTE_AUTHOR)); String quoteText = cursor.getString(cursor.getColumnIndexOrThrow(QUOTE_BODY)); boolean quoteMissing = cursor.getInt(cursor.getColumnIndexOrThrow(QUOTE_MISSING)) == 1; List quoteAttachments = Stream.of(associatedAttachments).filter(Attachment::isQuote).map(a -> (Attachment)a).toList(); @@ -641,8 +641,8 @@ public class MmsDatabase extends MessagingDatabase { List mismatches = new LinkedList<>(); QuoteModel quote = null; - if (quoteId > 0 && (!TextUtils.isEmpty(quoteText) || !quoteAttachments.isEmpty())) { - quote = new QuoteModel(quoteId, quoteAuthor, quoteText, quoteMissing, quoteAttachments); + if (quoteId > 0 && quoteAuthor > 0 && (!TextUtils.isEmpty(quoteText) || !quoteAttachments.isEmpty())) { + quote = new QuoteModel(quoteId, RecipientId.from(quoteAuthor), quoteText, quoteMissing, quoteAttachments); } if (!TextUtils.isEmpty(mismatchDocument)) { @@ -1538,15 +1538,15 @@ public class MmsDatabase extends MessagingDatabase { private @Nullable Quote getQuote(@NonNull Cursor cursor) { long quoteId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.QUOTE_ID)); - RecipientId quoteAuthor = RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.QUOTE_AUTHOR))); + long quoteAuthor = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.QUOTE_AUTHOR)); String quoteText = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.QUOTE_BODY)); boolean quoteMissing = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.QUOTE_MISSING)) == 1; List attachments = DatabaseFactory.getAttachmentDatabase(context).getAttachment(cursor); List quoteAttachments = Stream.of(attachments).filter(Attachment::isQuote).toList(); SlideDeck quoteDeck = new SlideDeck(context, quoteAttachments); - if (quoteId > 0 && !quoteAuthor.isUnknown()) { - return new Quote(quoteId, quoteAuthor, quoteText, quoteMissing, quoteDeck); + if (quoteId > 0 && quoteAuthor > 0) { + return new Quote(quoteId, RecipientId.from(quoteAuthor), quoteText, quoteMissing, quoteDeck); } else { return null; } diff --git a/src/org/thoughtcrime/securesms/recipients/RecipientId.java b/src/org/thoughtcrime/securesms/recipients/RecipientId.java index be23a92db1..cc0496489a 100644 --- a/src/org/thoughtcrime/securesms/recipients/RecipientId.java +++ b/src/org/thoughtcrime/securesms/recipients/RecipientId.java @@ -23,6 +23,10 @@ public class RecipientId implements Parcelable, Comparable { private final long id; public static RecipientId from(long id) { + if (id == 0) { + throw new AssertionError("Invalid ID!"); + } + return new RecipientId(id); }