Skip to content

Commit

Permalink
Disallow RecipientId's of zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Oct 18, 2019
1 parent 7193252 commit bcecc30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/org/thoughtcrime/securesms/database/MmsDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ public OutgoingMediaMessage getOutgoingMessage(long messageId)
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<Attachment> quoteAttachments = Stream.of(associatedAttachments).filter(Attachment::isQuote).map(a -> (Attachment)a).toList();
Expand All @@ -641,8 +641,8 @@ public OutgoingMediaMessage getOutgoingMessage(long messageId)
List<IdentityKeyMismatch> 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)) {
Expand Down Expand Up @@ -1538,15 +1538,15 @@ private SlideDeck getSlideDeck(@NonNull List<DatabaseAttachment> attachments) {

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<DatabaseAttachment> attachments = DatabaseFactory.getAttachmentDatabase(context).getAttachment(cursor);
List<? extends Attachment> 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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/org/thoughtcrime/securesms/recipients/RecipientId.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class RecipientId implements Parcelable, Comparable<RecipientId> {
private final long id;

public static RecipientId from(long id) {
if (id == 0) {
throw new AssertionError("Invalid ID!");
}

return new RecipientId(id);
}

Expand Down

0 comments on commit bcecc30

Please sign in to comment.