Fix possible crash in ProfileKeySendJob if given an invalid threadId.

fork-5.53.8
Greyson Parrelli 2022-07-01 11:06:37 -04:00
rodzic e413ee4ed9
commit be2ed8989f
5 zmienionych plików z 20 dodań i 10 usunięć

Wyświetl plik

@ -1153,7 +1153,6 @@ public class ThreadDatabase extends Database {
SQLiteDatabase db = databaseHelper.getSignalReadableDatabase(); SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
try (Cursor cursor = db.query(TABLE_NAME, RECIPIENT_ID_PROJECTION, ID_WHERE, SqlUtil.buildArgs(threadId), null, null, null)) { try (Cursor cursor = db.query(TABLE_NAME, RECIPIENT_ID_PROJECTION, ID_WHERE, SqlUtil.buildArgs(threadId), null, null, null)) {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
return RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(RECIPIENT_ID))); return RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(RECIPIENT_ID)));
} }

Wyświetl plik

@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.jobs;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread; import androidx.annotation.WorkerThread;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
@ -45,13 +46,16 @@ public class ProfileKeySendJob extends BaseJob {
* *
* @param queueLimits True if you only want one of these to be run per person after decryptions * @param queueLimits True if you only want one of these to be run per person after decryptions
* are drained, otherwise false. * are drained, otherwise false.
*
* @return The job that is created, or null if the threadId provided was invalid.
*/ */
@WorkerThread @WorkerThread
public static ProfileKeySendJob create(@NonNull Context context, long threadId, boolean queueLimits) { public static @Nullable ProfileKeySendJob create(long threadId, boolean queueLimits) {
Recipient conversationRecipient = SignalDatabase.threads().getRecipientForThreadId(threadId); Recipient conversationRecipient = SignalDatabase.threads().getRecipientForThreadId(threadId);
if (conversationRecipient == null) { if (conversationRecipient == null) {
throw new AssertionError("We have a thread but no recipient!"); Log.w(TAG, "Thread no longer valid! Aborting.");
return null;
} }
if (conversationRecipient.isPushV2Group()) { if (conversationRecipient.isPushV2Group()) {

Wyświetl plik

@ -144,7 +144,7 @@ final class MessageRequestRepository {
RecipientDatabase recipientDatabase = SignalDatabase.recipients(); RecipientDatabase recipientDatabase = SignalDatabase.recipients();
recipientDatabase.setProfileSharing(liveRecipient.getId(), true); recipientDatabase.setProfileSharing(liveRecipient.getId(), true);
MessageSender.sendProfileKey(context, threadId); MessageSender.sendProfileKey(threadId);
List<MessageDatabase.MarkedMessageInfo> messageIds = SignalDatabase.threads().setEntireThreadRead(threadId); List<MessageDatabase.MarkedMessageInfo> messageIds = SignalDatabase.threads().setEntireThreadRead(threadId);
ApplicationDependencies.getMessageNotifier().updateNotification(context); ApplicationDependencies.getMessageNotifier().updateNotification(context);

Wyświetl plik

@ -325,10 +325,14 @@ public final class MessageContentProcessor {
.enqueue(); .enqueue();
} else if (!threadRecipient.isGroup()) { } else if (!threadRecipient.isGroup()) {
Log.i(TAG, "Message was to a 1:1. Ensuring this user has our profile key."); Log.i(TAG, "Message was to a 1:1. Ensuring this user has our profile key.");
ApplicationDependencies.getJobManager() ProfileKeySendJob profileSendJob = ProfileKeySendJob.create(SignalDatabase.threads().getOrCreateThreadIdFor(threadRecipient), true);
.startChain(new RefreshAttributesJob(false))
.then(ProfileKeySendJob.create(context, SignalDatabase.threads().getOrCreateThreadIdFor(threadRecipient), true)) if (profileSendJob != null) {
.enqueue(); ApplicationDependencies.getJobManager()
.startChain(new RefreshAttributesJob(false))
.then(profileSendJob)
.enqueue();
}
} }
} }
} }

Wyświetl plik

@ -102,8 +102,11 @@ public class MessageSender {
* Suitable for a 1:1 conversation or a GV1 group only. * Suitable for a 1:1 conversation or a GV1 group only.
*/ */
@WorkerThread @WorkerThread
public static void sendProfileKey(final Context context, final long threadId) { public static void sendProfileKey(final long threadId) {
ApplicationDependencies.getJobManager().add(ProfileKeySendJob.create(context, threadId, false)); ProfileKeySendJob job = ProfileKeySendJob.create(threadId, false);
if (job != null) {
ApplicationDependencies.getJobManager().add(job);
}
} }
public static long send(final Context context, public static long send(final Context context,