Prevent setting a null profile key during account restore.

fork-5.53.8
Greyson Parrelli 2022-08-09 10:53:31 -04:00
rodzic 29a9297452
commit 055b79c9f2
2 zmienionych plików z 14 dodań i 3 usunięć

Wyświetl plik

@ -1025,17 +1025,24 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
val profileName = ProfileName.fromParts(update.new.givenName.orElse(null), update.new.familyName.orElse(null))
val localKey = ProfileKeyUtil.profileKeyOptional(update.old.profileKey.orElse(null))
val remoteKey = ProfileKeyUtil.profileKeyOptional(update.new.profileKey.orElse(null))
val profileKey = remoteKey.or(localKey).map { obj: ProfileKey -> obj.serialize() }.map { source: ByteArray? -> Base64.encodeBytes(source!!) }.orElse(null)
val profileKey: String? = remoteKey.or(localKey).map { obj: ProfileKey -> obj.serialize() }.map { source: ByteArray? -> Base64.encodeBytes(source!!) }.orElse(null)
if (!remoteKey.isPresent) {
Log.w(TAG, "Got an empty profile key while applying an account record update!")
Log.w(TAG, "Got an empty profile key while applying an account record update! The parsed local key is ${if (localKey.isPresent) "present" else "not present"}. The raw local key is ${if (update.old.profileKey.isPresent) "present" else "not present"}. The resulting key is ${if (profileKey != null) "present" else "not present"}.")
}
val values = ContentValues().apply {
put(PROFILE_GIVEN_NAME, profileName.givenName)
put(PROFILE_FAMILY_NAME, profileName.familyName)
put(PROFILE_JOINED_NAME, profileName.toString())
put(PROFILE_KEY, profileKey)
if (profileKey != null) {
put(PROFILE_KEY, profileKey)
} else {
Log.w(TAG, "Avoided attempt to apply null profile key in account record update!")
}
put(STORAGE_SERVICE_ID, Base64.encodeBytes(update.new.id.raw))
if (update.new.hasUnknownFields()) {
put(STORAGE_PROTO, Base64.encodeBytes(Objects.requireNonNull(update.new.serializeUnknownFields())))
} else {

Wyświetl plik

@ -146,6 +146,10 @@ public final class StorageSyncValidations {
throw new SelfAddedAsContactError();
}
}
if (insert.getAccount().isPresent() && !insert.getAccount().get().getProfileKey().isPresent()) {
Log.w(TAG, "Uploading a null profile key in our AccountRecord!");
}
}
}