From fed4899c8db6587eab3a7657a2ba3ecce6bc0102 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 15 Mar 2019 10:01:57 -0400 Subject: [PATCH] Handle incoming attachments with missing MIME type. --- .../Messages/Attachments/TSAttachmentPointer.m | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.m b/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.m index e967ed40d..da2684f01 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentPointer.m @@ -116,9 +116,17 @@ NS_ASSUME_NONNULL_BEGIN OWSFailDebug(@"Invalid attachment key."); return nil; } - if (attachmentProto.contentType.length < 1) { - OWSFailDebug(@"Invalid attachment content type."); - return nil; + NSString *_Nullable fileName = attachmentProto.fileName; + NSString *_Nullable contentType = attachmentProto.contentType; + if (contentType.length < 1) { + OWSLogError(@"Invalid attachment content type."); + NSString *_Nullable fileExtension = [fileName pathExtension].lowercaseString; + if (fileExtension.length > 0) { + contentType = [MIMETypeUtil mimeTypeForFileExtension:fileExtension]; + } + if (contentType.length < 1) { + contentType = OWSMimeTypeApplicationOctetStream; + } } // digest will be empty for old clients. @@ -151,8 +159,8 @@ NS_ASSUME_NONNULL_BEGIN key:attachmentProto.key digest:digest byteCount:attachmentProto.size - contentType:attachmentProto.contentType - sourceFilename:attachmentProto.fileName + contentType:contentType + sourceFilename:fileName caption:caption albumMessageId:albumMessageId attachmentType:attachmentType