Merge branch 'charlesmchen/unsafeFilenameCharacters' into hotfix/2.20.1

pull/1/head
Matthew Chen 7 years ago
commit 815c9af150

@ -284,6 +284,10 @@ NS_ASSUME_NONNULL_BEGIN
actionBlock:^{ actionBlock:^{
[DebugUIMessages testZalgoTextInThread:thread]; [DebugUIMessages testZalgoTextInThread:thread];
}], }],
[OWSTableItem itemWithTitle:@"Test Directional Filenames"
actionBlock:^{
[DebugUIMessages testDirectionalFilenamesInThread:thread];
}],
] mutableCopy]; ] mutableCopy];
if ([thread isKindOfClass:[TSContactThread class]]) { if ([thread isKindOfClass:[TSContactThread class]]) {
TSContactThread *contactThread = (TSContactThread *)thread; TSContactThread *contactThread = (TSContactThread *)thread;
@ -1684,6 +1688,43 @@ NS_ASSUME_NONNULL_BEGIN
}]; }];
} }
+ (void)testDirectionalFilenamesInThread:(TSThread *)thread
{
NSMutableArray<NSString *> *filenames = [@[
@"a_test\u202Dabc.exe",
@"b_test\u202Eabc.exe",
@"c_testabc.exe",
] mutableCopy];
__block void (^sendUnsafeFile)(void);
sendUnsafeFile = ^{
if (filenames.count < 1) {
return;
}
NSString *filename = filenames.lastObject;
[filenames removeLastObject];
OWSMessageSender *messageSender = [Environment current].messageSender;
NSString *utiType = (NSString *)kUTTypeData;
const NSUInteger kDataLength = 32;
DataSource *_Nullable dataSource =
[DataSourceValue dataSourceWithData:[self createRandomNSDataOfSize:kDataLength] utiType:utiType];
[dataSource setSourceFilename:filename];
SignalAttachment *attachment =
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:utiType imageQuality:TSImageQualityOriginal];
OWSAssert(attachment);
if ([attachment hasError]) {
DDLogError(@"attachment[%@]: %@", [attachment sourceFilename], [attachment errorName]);
[DDLog flushLog];
}
OWSAssert(![attachment hasError]);
[ThreadUtil sendMessageWithAttachment:attachment inThread:thread messageSender:messageSender completion:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
sendUnsafeFile();
});
};
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -130,7 +130,7 @@ public class SignalAttachment: NSObject {
@objc @objc
public var sourceFilename: String? { public var sourceFilename: String? {
return dataSource.sourceFilename?.filterStringForDisplay() return dataSource.sourceFilename?.filterFilename()
} }
@objc @objc
@ -311,7 +311,7 @@ public class SignalAttachment: NSObject {
@objc @objc
public var filenameOrDefault: String { public var filenameOrDefault: String {
if let filename = sourceFilename { if let filename = sourceFilename {
return filename.filterStringForDisplay() return filename.filterFilename()
} else { } else {
let kDefaultAttachmentName = "signal" let kDefaultAttachmentName = "signal"
@ -335,7 +335,7 @@ public class SignalAttachment: NSObject {
if let filename = sourceFilename { if let filename = sourceFilename {
let fileExtension = (filename as NSString).pathExtension let fileExtension = (filename as NSString).pathExtension
if fileExtension.count > 0 { if fileExtension.count > 0 {
return fileExtension.filterStringForDisplay() return fileExtension.filterFilename()
} }
} }
if isOversizeText { if isOversizeText {

@ -192,12 +192,12 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
- (nullable NSString *)sourceFilename - (nullable NSString *)sourceFilename
{ {
return _sourceFilename.filterStringForDisplay; return _sourceFilename.filterFilename;
} }
- (NSString *)contentType - (NSString *)contentType
{ {
return _contentType.filterStringForDisplay; return _contentType.filterFilename;
} }
@end @end

@ -529,6 +529,7 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
[builder setId:attachmentStream.serverId]; [builder setId:attachmentStream.serverId];
OWSAssert(attachmentStream.contentType.length > 0); OWSAssert(attachmentStream.contentType.length > 0);
[builder setContentType:attachmentStream.contentType]; [builder setContentType:attachmentStream.contentType];
DDLogVerbose(@"%@ Sending attachment with filename: '%@'", self.logTag, filename);
[builder setFileName:filename]; [builder setFileName:filename];
[builder setSize:attachmentStream.byteCount]; [builder setSize:attachmentStream.byteCount];
[builder setKey:attachmentStream.encryptionKey]; [builder setKey:attachmentStream.encryptionKey];

@ -357,7 +357,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
ofClass:[TSOutgoingMessage class] ofClass:[TSOutgoingMessage class]
withTransaction:transaction]; withTransaction:transaction];
if (messages.count > 1) { if (messages.count > 1) {
OWSFail(@"%@ More than one matching message with timestamp: %llu.", self.logTag, sentTimestamp); DDLogError(@"%@ More than one matching message with timestamp: %llu.", self.logTag, sentTimestamp);
} }
if (messages.count > 0) { if (messages.count > 0) {
// TODO: We might also need to "mark as read by recipient" any older messages // TODO: We might also need to "mark as read by recipient" any older messages

@ -80,7 +80,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setSourceFilename:(nullable NSString *)sourceFilename - (void)setSourceFilename:(nullable NSString *)sourceFilename
{ {
_sourceFilename = sourceFilename.filterStringForDisplay; _sourceFilename = sourceFilename.filterFilename;
} }
@end @end

@ -10,6 +10,8 @@ NS_ASSUME_NONNULL_BEGIN
- (NSString *)filterStringForDisplay; - (NSString *)filterStringForDisplay;
- (NSString *)filterFilename;
- (BOOL)isValidE164; - (BOOL)isValidE164;
@end @end

@ -144,7 +144,7 @@ NS_ASSUME_NONNULL_BEGIN
return [filteredForIndic copy]; return [filteredForIndic copy];
} }
+ (NSCharacterSet *)unsafeCharacterSet + (NSCharacterSet *)unsafeFilenameCharacterSet
{ {
static NSCharacterSet *characterSet; static NSCharacterSet *characterSet;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
@ -160,9 +160,9 @@ NS_ASSUME_NONNULL_BEGIN
return characterSet; return characterSet;
} }
- (NSString *)filterUnsafeCharacters - (NSString *)filterUnsafeFilenameCharacters
{ {
NSCharacterSet *unsafeCharacterSet = [[self class] unsafeCharacterSet]; NSCharacterSet *unsafeCharacterSet = [[self class] unsafeFilenameCharacterSet];
NSRange range = [self rangeOfCharacterFromSet:unsafeCharacterSet]; NSRange range = [self rangeOfCharacterFromSet:unsafeCharacterSet];
if (range.location == NSNotFound) { if (range.location == NSNotFound) {
return self; return self;
@ -184,7 +184,12 @@ NS_ASSUME_NONNULL_BEGIN
- (NSString *)filterStringForDisplay - (NSString *)filterStringForDisplay
{ {
return self.ows_stripped.filterForIndicScripts.filterForExcessiveDiacriticals.filterUnsafeCharacters; return self.ows_stripped.filterForIndicScripts.filterForExcessiveDiacriticals;
}
- (NSString *)filterFilename
{
return self.ows_stripped.filterForIndicScripts.filterForExcessiveDiacriticals.filterUnsafeFilenameCharacters;
} }
- (NSString *)filterForExcessiveDiacriticals - (NSString *)filterForExcessiveDiacriticals

Loading…
Cancel
Save