diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachment.m b/SignalServiceKit/src/Messages/Attachments/TSAttachment.m index 4bea23d36..c2d5c1565 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachment.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachment.m @@ -31,6 +31,11 @@ NSUInteger const TSAttachmentSchemaVersion = 4; // This will fail with legacy iOS clients which don't upload attachment size. DDLogWarn(@"%@ Missing byteCount for attachment with serverId: %lld", self.tag, serverId); } + if (contentType.length < 1) { + DDLogWarn(@"%@ incoming attachment has invalid content type", self.tag); + + contentType = OWSMimeTypeApplicationOctetStream; + } OWSAssert(contentType.length > 0); self = [super init]; @@ -55,6 +60,11 @@ NSUInteger const TSAttachmentSchemaVersion = 4; byteCount:(UInt32)byteCount sourceFilename:(nullable NSString *)sourceFilename { + if (contentType.length < 1) { + DDLogWarn(@"%@ outgoing attachment has invalid content type", self.tag); + + contentType = OWSMimeTypeApplicationOctetStream; + } OWSAssert(contentType.length > 0); OWSAssert(byteCount > 0); @@ -93,8 +103,14 @@ NSUInteger const TSAttachmentSchemaVersion = 4; _serverId = pointer.serverId; _encryptionKey = pointer.encryptionKey; _byteCount = pointer.byteCount; - _contentType = pointer.contentType; _sourceFilename = pointer.sourceFilename; + NSString *contentType = pointer.contentType; + if (contentType.length < 1) { + DDLogWarn(@"%@ incoming attachment has invalid content type", self.tag); + + contentType = OWSMimeTypeApplicationOctetStream; + } + _contentType = contentType; _attachmentSchemaVersion = TSAttachmentSchemaVersion; @@ -119,6 +135,12 @@ NSUInteger const TSAttachmentSchemaVersion = 4; OWSAssert(!_sourceFilename || [_sourceFilename isKindOfClass:[NSString class]]); } + if (_contentType.length < 1) { + DDLogWarn(@"%@ legacy attachment has invalid content type", self.tag); + + _contentType = OWSMimeTypeApplicationOctetStream; + } + return self; } diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m index 0c783c7d2..2bc575a28 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m @@ -541,6 +541,7 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec OWSSignalServiceProtosAttachmentPointerBuilder *builder = [OWSSignalServiceProtosAttachmentPointerBuilder new]; [builder setId:attachmentStream.serverId]; + OWSAssert(attachmentStream.contentType.length > 0); [builder setContentType:attachmentStream.contentType]; [builder setFileName:filename]; [builder setSize:attachmentStream.byteCount];