From 36a9d9cec9a8626f43e7654f0e064c0f1daafa37 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Wed, 27 Sep 2023 16:28:39 +0200 Subject: [PATCH 1/2] Prevent crash when sending file with unrecognised file extension (no associated mime type) Signed-off-by: Nicolas Buquet --- MatrixSDK/Data/MXRoom.m | 8 ++++---- changelog.d/mimetype.bugfix | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 changelog.d/mimetype.bugfix diff --git a/MatrixSDK/Data/MXRoom.m b/MatrixSDK/Data/MXRoom.m index b626989f0b..fe1a3a167b 100644 --- a/MatrixSDK/Data/MXRoom.m +++ b/MatrixSDK/Data/MXRoom.m @@ -1020,7 +1020,7 @@ - (MXHTTPOperation*)sendImage:(NSData*)imageData kMXMessageBodyKey: filename, @"url": fakeMediaURI, @"info": [@{ - @"mimetype": mimetype, + @"mimetype": (mimeType ?: @"@application/octet-stream"), @"w": @(imageSize.width), @"h": @(imageSize.height), @"size": @(imageData.length) @@ -1347,7 +1347,7 @@ - (MXHTTPOperation*)sendVideoAsset:(AVAsset*)videoAsset } // update metadata with result of converter output - msgContent[@"info"][@"mimetype"] = mimetype; + msgContent[@"info"][@"mimetype"] = (mimeType ?: @"@application/octet-stream"); msgContent[@"info"][@"w"] = @(size.width); msgContent[@"info"][@"h"] = @(size.height); msgContent[@"info"][@"duration"] = @((int)floor(durationInMs)); @@ -1670,7 +1670,7 @@ - (MXHTTPOperation*)_sendFile:(NSURL*)fileLocalURL kMXMessageBodyKey: filename, @"url": fakeMediaURI, @"info": @{ - @"mimetype": mimeType, + @"mimetype": (mimeType ?: @"@application/octet-stream"), @"size": @(fileData.length) }, kMXMessageContentKeyExtensibleTextMSC1767: filename, @@ -1678,7 +1678,7 @@ - (MXHTTPOperation*)_sendFile:(NSURL*)fileLocalURL kMXMessageContentKeyExtensibleFileSize: @(fileData.length), kMXMessageContentKeyExtensibleFileName: filename, kMXMessageContentKeyExtensibleFileURL: fakeMediaURI, - kMXMessageContentKeyExtensibleFileMimeType: mimeType + kMXMessageContentKeyExtensibleFileMimeType: (mimeType ?: @"@application/octet-stream") }.mutableCopy}.mutableCopy; if(additionalTypes.count) diff --git a/changelog.d/mimetype.bugfix b/changelog.d/mimetype.bugfix new file mode 100644 index 0000000000..e4287e0b86 --- /dev/null +++ b/changelog.d/mimetype.bugfix @@ -0,0 +1 @@ +Prevent crash when sending file with unrecognised file extension (no associated mime type) \ No newline at end of file From 3bed91443a0e8cf7bfe850dde38dc13e5ef99c9b Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Fri, 29 Sep 2023 06:56:23 +0200 Subject: [PATCH 2/2] Fix incorrect @ NSString marker --- MatrixSDK/Data/MXRoom.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MatrixSDK/Data/MXRoom.m b/MatrixSDK/Data/MXRoom.m index fe1a3a167b..8cfad29c11 100644 --- a/MatrixSDK/Data/MXRoom.m +++ b/MatrixSDK/Data/MXRoom.m @@ -1020,7 +1020,7 @@ - (MXHTTPOperation*)sendImage:(NSData*)imageData kMXMessageBodyKey: filename, @"url": fakeMediaURI, @"info": [@{ - @"mimetype": (mimeType ?: @"@application/octet-stream"), + @"mimetype": (mimeType ?: @"application/octet-stream"), @"w": @(imageSize.width), @"h": @(imageSize.height), @"size": @(imageData.length) @@ -1347,7 +1347,7 @@ - (MXHTTPOperation*)sendVideoAsset:(AVAsset*)videoAsset } // update metadata with result of converter output - msgContent[@"info"][@"mimetype"] = (mimeType ?: @"@application/octet-stream"); + msgContent[@"info"][@"mimetype"] = (mimeType ?: @"application/octet-stream"); msgContent[@"info"][@"w"] = @(size.width); msgContent[@"info"][@"h"] = @(size.height); msgContent[@"info"][@"duration"] = @((int)floor(durationInMs)); @@ -1670,7 +1670,7 @@ - (MXHTTPOperation*)_sendFile:(NSURL*)fileLocalURL kMXMessageBodyKey: filename, @"url": fakeMediaURI, @"info": @{ - @"mimetype": (mimeType ?: @"@application/octet-stream"), + @"mimetype": (mimeType ?: @"application/octet-stream"), @"size": @(fileData.length) }, kMXMessageContentKeyExtensibleTextMSC1767: filename, @@ -1678,7 +1678,7 @@ - (MXHTTPOperation*)_sendFile:(NSURL*)fileLocalURL kMXMessageContentKeyExtensibleFileSize: @(fileData.length), kMXMessageContentKeyExtensibleFileName: filename, kMXMessageContentKeyExtensibleFileURL: fakeMediaURI, - kMXMessageContentKeyExtensibleFileMimeType: (mimeType ?: @"@application/octet-stream") + kMXMessageContentKeyExtensibleFileMimeType: (mimeType ?: @"application/octet-stream") }.mutableCopy}.mutableCopy; if(additionalTypes.count)