Fix crash when downloading attachment from S3.

This commit is contained in:
Greyson Parrelli 2024-09-10 20:47:13 -04:00 committed by Cody Henthorne
parent 36a8a399d9
commit 7735ca9dab
2 changed files with 8 additions and 3 deletions

View file

@ -981,9 +981,10 @@ class AttachmentTable(
limitStream.leftoverStream().allMatch { it == 0x00.toByte() }
}
val digest = if (paddingAllZeroes) {
// Existing digest may be null for non-user attachments, like things pulled from S3
val digest = if (existingPlaceholder.remoteDigest != null && paddingAllZeroes) {
Log.d(TAG, "[finalizeAttachmentAfterDownload] $attachmentId has all-zero padding. Digest is good.")
existingPlaceholder.remoteDigest!!
existingPlaceholder.remoteDigest
} else {
Log.w(TAG, "[finalizeAttachmentAfterDownload] $attachmentId has non-zero padding bytes. Recomputing digest.")

View file

@ -416,11 +416,15 @@ class AttachmentDownloadJob private constructor(
if (body.contentLength() > RemoteConfig.maxAttachmentReceiveSizeBytes) {
throw MmsException("Attachment too large, failing download")
}
SignalDatabase.attachments.createKeyIvIfNecessary(attachmentId)
val updatedAttachment = SignalDatabase.attachments.getAttachment(attachmentId)!!
SignalDatabase.attachments.finalizeAttachmentAfterDownload(
messageId,
attachmentId,
LimitedInputStream.withoutLimits((body.source() as Source).buffer().inputStream()),
iv = null
iv = updatedAttachment.remoteIv
)
}
}