Ensure attachments always have a valid content type.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 5548030bde
commit 4d57402367

@ -31,6 +31,11 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
// This will fail with legacy iOS clients which don't upload attachment size. // This will fail with legacy iOS clients which don't upload attachment size.
DDLogWarn(@"%@ Missing byteCount for attachment with serverId: %lld", self.tag, serverId); 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 = @"application/octet-stream";
}
OWSAssert(contentType.length > 0); OWSAssert(contentType.length > 0);
self = [super init]; self = [super init];
@ -55,6 +60,11 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
byteCount:(UInt32)byteCount byteCount:(UInt32)byteCount
sourceFilename:(nullable NSString *)sourceFilename sourceFilename:(nullable NSString *)sourceFilename
{ {
if (contentType.length < 1) {
DDLogWarn(@"%@ outgoing attachment has invalid content type", self.tag);
contentType = @"application/octet-stream";
}
OWSAssert(contentType.length > 0); OWSAssert(contentType.length > 0);
OWSAssert(byteCount > 0); OWSAssert(byteCount > 0);
@ -93,8 +103,14 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
_serverId = pointer.serverId; _serverId = pointer.serverId;
_encryptionKey = pointer.encryptionKey; _encryptionKey = pointer.encryptionKey;
_byteCount = pointer.byteCount; _byteCount = pointer.byteCount;
_contentType = pointer.contentType;
_sourceFilename = pointer.sourceFilename; _sourceFilename = pointer.sourceFilename;
NSString *contentType = pointer.contentType;
if (contentType.length < 1) {
DDLogWarn(@"%@ incoming attachment has invalid content type", self.tag);
contentType = @"application/octet-stream";
}
_contentType = contentType;
_attachmentSchemaVersion = TSAttachmentSchemaVersion; _attachmentSchemaVersion = TSAttachmentSchemaVersion;
@ -119,6 +135,12 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
OWSAssert(!_sourceFilename || [_sourceFilename isKindOfClass:[NSString class]]); OWSAssert(!_sourceFilename || [_sourceFilename isKindOfClass:[NSString class]]);
} }
if (_contentType.length < 1) {
DDLogWarn(@"%@ legacy attachment has invalid content type", self.tag);
_contentType = @"application/octet-stream";
}
return self; return self;
} }

@ -541,6 +541,8 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
OWSSignalServiceProtosAttachmentPointerBuilder *builder = [OWSSignalServiceProtosAttachmentPointerBuilder new]; OWSSignalServiceProtosAttachmentPointerBuilder *builder = [OWSSignalServiceProtosAttachmentPointerBuilder new];
[builder setId:attachmentStream.serverId]; [builder setId:attachmentStream.serverId];
NSString *contentType = attachmentStream.contentType;
OWSAssert(attachmentStream.contentType.length > 0);
[builder setContentType:attachmentStream.contentType]; [builder setContentType:attachmentStream.contentType];
[builder setFileName:filename]; [builder setFileName:filename];
[builder setSize:attachmentStream.byteCount]; [builder setSize:attachmentStream.byteCount];

Loading…
Cancel
Save