From ec07e4b233015949004de4ee5b7baeae1d011cf3 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Sat, 13 Mar 2021 11:50:10 -0500 Subject: [PATCH] Avoid possibility of walking outside a contact cursor. --- .../thoughtcrime/securesms/contacts/sync/DirectoryHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/sync/DirectoryHelper.java b/app/src/main/java/org/thoughtcrime/securesms/contacts/sync/DirectoryHelper.java index 128775eee..96657e35f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/sync/DirectoryHelper.java +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/sync/DirectoryHelper.java @@ -334,7 +334,7 @@ public class DirectoryHelper { Log.w(TAG, "Ignoring unexpected mime type: " + mimeType); } - while (getLookupKey(cursor).equals(lookupKey) && isPhoneMimeType(getMimeType(cursor))) { + while (!cursor.isAfterLast() && getLookupKey(cursor).equals(lookupKey) && isPhoneMimeType(getMimeType(cursor))) { String number = CursorUtil.requireString(cursor, ContactsContract.CommonDataKinds.Phone.NUMBER); if (isValidContactNumber(number)) { @@ -359,7 +359,7 @@ public class DirectoryHelper { cursor.moveToNext(); } - if (getLookupKey(cursor).equals(lookupKey)) { + if (!cursor.isAfterLast() && getLookupKey(cursor).equals(lookupKey)) { if (isStructuredNameMimeType(getMimeType(cursor))) { StructuredNameRecord.Builder builder = new StructuredNameRecord.Builder();