From 3c2846274cd4d1c788c478ea3fcdcc98b1f03ae0 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 21 Jul 2016 15:55:32 -0700 Subject: [PATCH] Prevent crash when copying corrupted image attachment. (#1287) // FREEBIE --- Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.m b/Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.m index 5df6e5106..cd12927c3 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.m +++ b/Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.m @@ -85,6 +85,15 @@ - (void)performEditingAction:(SEL)action { + NSString *actionString = NSStringFromSelector(action); + if (!self.image) { + DDLogWarn(@"Refusing to perform '%@' action with nil image for %@: attachmentId=%@. (corrupted attachment?)", + actionString, + self.class, + self.attachmentId); + return; + } + if (action == @selector(copy:)) { UIPasteboard.generalPasteboard.image = self.image; return; @@ -94,7 +103,6 @@ } // Shouldn't get here, as only supported actions should be exposed via canPerformEditingAction - NSString *actionString = NSStringFromSelector(action); DDLogError(@"'%@' action unsupported for %@: attachmentId=%@", actionString, self.class, self.attachmentId); }