Add additional download checks to long message text attachments.

This commit is contained in:
Cody Henthorne
2026-05-18 15:37:22 -04:00
committed by jeffrey-signal
parent 5052f22d44
commit 5321f8124a
3 changed files with 15 additions and 3 deletions
@@ -38,6 +38,8 @@ import org.thoughtcrime.securesms.notifications.v2.ConversationId.Companion.forC
import org.thoughtcrime.securesms.s3.S3
import org.thoughtcrime.securesms.transport.RetryLaterException
import org.thoughtcrime.securesms.util.AttachmentUtil
import org.thoughtcrime.securesms.util.MediaUtil
import org.thoughtcrime.securesms.util.MessageUtil
import org.thoughtcrime.securesms.util.RemoteConfig
import org.whispersystems.signalservice.api.crypto.AttachmentCipherInputStream.IntegrityCheck
import org.whispersystems.signalservice.api.crypto.AttachmentCipherStreamUtil
@@ -301,6 +303,10 @@ class AttachmentDownloadJob private constructor(
throw MmsException("[$attachmentId] Attachment too large, failing download")
}
if (MediaUtil.isLongTextType(attachment.contentType) && attachment.size > MessageUtil.MAX_TOTAL_BODY_SIZE_BYTES) {
throw InvalidAttachmentException("[$attachmentId] Long-text attachment exceeds ${MessageUtil.MAX_TOTAL_BODY_SIZE_BYTES} byte cap, declared size: ${attachment.size}")
}
val pointer = createAttachmentPointer(attachment)
val progressListener = object : SignalServiceAttachment.ProgressListener {
@@ -73,7 +73,7 @@ object AttachmentUtil {
val contentType = attachment.contentType
return when {
MediaUtil.isLongTextType(contentType) -> true
MediaUtil.isLongTextType(contentType) -> attachment.size <= MessageUtil.MAX_TOTAL_BODY_SIZE_BYTES
attachment.isSticker -> ciphertextSize <= SMALL_ATTACHMENT_SIZE || allowedForType(allowedTypes, "image", "sticker")
attachment.voiceNote -> ciphertextSize <= SMALL_ATTACHMENT_SIZE || allowedForType(allowedTypes, "audio", "voice message")
attachment.videoGif -> allowedForType(allowedTypes, "image", "video gif")