Fix crash importing recipients without identifiers.

This commit is contained in:
Cody Henthorne
2025-10-16 14:58:44 -04:00
parent 6ea0e176c9
commit 3346497a25
3 changed files with 17 additions and 3 deletions

View File

@@ -203,6 +203,10 @@ object ExportOddities {
* These represent situations where we will skip importing a data frame due to the data being invalid.
*/
object ImportSkips {
fun recipientWithoutId(): String {
return log(0, " No aci, pni, or e164 available for recipient")
}
fun fromRecipientNotFound(sentTimestamp: Long): String {
return log(sentTimestamp, "Failed to find the fromRecipient for the message.")
}

View File

@@ -8,8 +8,10 @@ package org.thoughtcrime.securesms.backup.v2.importer
import androidx.core.content.contentValuesOf
import org.signal.core.util.Base64
import org.signal.core.util.insertInto
import org.signal.core.util.logging.Log
import org.signal.core.util.toInt
import org.signal.core.util.update
import org.thoughtcrime.securesms.backup.v2.ImportSkips
import org.thoughtcrime.securesms.backup.v2.proto.Contact
import org.thoughtcrime.securesms.backup.v2.util.toLocal
import org.thoughtcrime.securesms.database.IdentityTable
@@ -28,14 +30,22 @@ import org.whispersystems.signalservice.api.push.ServiceId.PNI
* Handles the importing of [Contact] models into the local database.
*/
object ContactArchiveImporter {
fun import(contact: Contact): RecipientId {
private val TAG = Log.tag(ContactArchiveImporter::class)
fun import(contact: Contact): RecipientId? {
val aci = ACI.parseOrNull(contact.aci?.toByteArray())
val pni = PNI.parseOrNull(contact.pni?.toByteArray())
val e164 = contact.formattedE164
if (aci == null && pni == null && e164 == null) {
Log.w(TAG, ImportSkips.recipientWithoutId())
return null
}
val id = SignalDatabase.recipients.getAndPossiblyMergePnpVerified(
aci = aci,
pni = pni,
e164 = contact.formattedE164
e164 = e164
)
val profileKey = contact.profileKey?.toByteArray()

View File

@@ -98,7 +98,7 @@ object RecipientArchiveProcessor {
}
fun import(recipient: ArchiveRecipient, importState: ImportState) {
val newId = when {
val newId: RecipientId? = when {
recipient.contact != null -> ContactArchiveImporter.import(recipient.contact)
recipient.group != null -> GroupArchiveImporter.import(recipient.group)
recipient.distributionList != null -> DistributionListArchiveImporter.import(recipient.distributionList, importState)