Skip to content

Commit 7735ca9

Browse files
greyson-signalcody-signal
authored andcommitted
Fix crash when downloading attachment from S3.
1 parent 36a8a39 commit 7735ca9

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

app/src/main/java/org/thoughtcrime/securesms/database/AttachmentTable.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,9 +981,10 @@ class AttachmentTable(
981981
limitStream.leftoverStream().allMatch { it == 0x00.toByte() }
982982
}
983983

984-
val digest = if (paddingAllZeroes) {
984+
// Existing digest may be null for non-user attachments, like things pulled from S3
985+
val digest = if (existingPlaceholder.remoteDigest != null && paddingAllZeroes) {
985986
Log.d(TAG, "[finalizeAttachmentAfterDownload] $attachmentId has all-zero padding. Digest is good.")
986-
existingPlaceholder.remoteDigest!!
987+
existingPlaceholder.remoteDigest
987988
} else {
988989
Log.w(TAG, "[finalizeAttachmentAfterDownload] $attachmentId has non-zero padding bytes. Recomputing digest.")
989990

app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,15 @@ class AttachmentDownloadJob private constructor(
416416
if (body.contentLength() > RemoteConfig.maxAttachmentReceiveSizeBytes) {
417417
throw MmsException("Attachment too large, failing download")
418418
}
419+
420+
SignalDatabase.attachments.createKeyIvIfNecessary(attachmentId)
421+
val updatedAttachment = SignalDatabase.attachments.getAttachment(attachmentId)!!
422+
419423
SignalDatabase.attachments.finalizeAttachmentAfterDownload(
420424
messageId,
421425
attachmentId,
422426
LimitedInputStream.withoutLimits((body.source() as Source).buffer().inputStream()),
423-
iv = null
427+
iv = updatedAttachment.remoteIv
424428
)
425429
}
426430
}

0 commit comments

Comments
 (0)