mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-24 19:56:00 +00:00
Fix crash when remote key is missing but not null.
This commit is contained in:
@@ -724,7 +724,7 @@ class AttachmentTable(
|
||||
$ARCHIVE_TRANSFER_STATE = ${ArchiveTransferState.NONE.value} AND
|
||||
$DATA_FILE NOT NULL AND
|
||||
$TRANSFER_STATE = $TRANSFER_PROGRESS_DONE AND
|
||||
$REMOTE_KEY IS NULL
|
||||
($REMOTE_KEY IS NULL OR LENGTH($REMOTE_KEY) = 0)
|
||||
"""
|
||||
)
|
||||
.run()
|
||||
@@ -1845,13 +1845,11 @@ class AttachmentTable(
|
||||
fun createRemoteKeyIfNecessary(attachmentId: AttachmentId) {
|
||||
val key = Util.getSecretBytes(64)
|
||||
|
||||
writableDatabase.withinTransaction {
|
||||
writableDatabase
|
||||
.update(TABLE_NAME)
|
||||
.values(REMOTE_KEY to Base64.encodeWithPadding(key))
|
||||
.where("$ID = ? AND $REMOTE_KEY IS NULL", attachmentId.id)
|
||||
.run()
|
||||
}
|
||||
writableDatabase
|
||||
.update(TABLE_NAME)
|
||||
.values(REMOTE_KEY to Base64.encodeWithPadding(key))
|
||||
.where("$ID = ? AND ($REMOTE_KEY IS NULL OR LENGTH($REMOTE_KEY) = 0)", attachmentId.id)
|
||||
.run()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -145,6 +145,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V287_FixInvalidArch
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V288_CopyStickerDataHashStartToEnd
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V289_AddQuoteTargetContentTypeColumn
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V290_AddArchiveThumbnailTransferStateColumn
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V291_NullOutRemoteKeyIfEmpty
|
||||
import org.thoughtcrime.securesms.database.SQLiteDatabase as SignalSqliteDatabase
|
||||
|
||||
/**
|
||||
@@ -295,10 +296,11 @@ object SignalDatabaseMigrations {
|
||||
287 to V287_FixInvalidArchiveState,
|
||||
288 to V288_CopyStickerDataHashStartToEnd,
|
||||
289 to V289_AddQuoteTargetContentTypeColumn,
|
||||
290 to V290_AddArchiveThumbnailTransferStateColumn
|
||||
290 to V290_AddArchiveThumbnailTransferStateColumn,
|
||||
291 to V291_NullOutRemoteKeyIfEmpty
|
||||
)
|
||||
|
||||
const val DATABASE_VERSION = 290
|
||||
const val DATABASE_VERSION = 291
|
||||
|
||||
@JvmStatic
|
||||
fun migrate(context: Application, db: SignalSqliteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.thoughtcrime.securesms.database.helpers.migration
|
||||
|
||||
import android.app.Application
|
||||
import org.thoughtcrime.securesms.database.SQLiteDatabase
|
||||
|
||||
/**
|
||||
* If remote_key is an empty byte array (base64 encoded), replace with null.
|
||||
*/
|
||||
@Suppress("ClassName")
|
||||
object V291_NullOutRemoteKeyIfEmpty : SignalDatabaseMigration {
|
||||
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
db.execSQL("UPDATE attachment SET remote_key = NULL WHERE remote_key IS NOT NULL AND LENGTH(remote_key) = 0")
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ class UploadAttachmentToArchiveJob private constructor(
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
if (attachment.remoteKey == null) {
|
||||
if (attachment.remoteKey == null || attachment.remoteKey.isBlank()) {
|
||||
Log.w(TAG, "[$attachmentId] Attachment is missing remote key! Cannot upload.")
|
||||
return Result.failure()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user