Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Crash when sending file with unrecognized extension #1821

Open
NicolasBuquet opened this issue Sep 27, 2023 · 1 comment
Open

Crash when sending file with unrecognized extension #1821

NicolasBuquet opened this issue Sep 27, 2023 · 1 comment

Comments

@NicolasBuquet
Copy link
Contributor

In a room, if I send a file attachment with unrecognized extension, the application crashes.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'

The crash occurs here :

    // Prepare the message content for building an echo message
    NSMutableDictionary *msgContent = @{
        kMXMessageTypeKey: msgType,
        kMXMessageBodyKey: filename,
        @"url": fakeMediaURI,
        @"info": @{
                @"mimetype": mimeType,
                @"size": @(fileData.length)
        },
        kMXMessageContentKeyExtensibleTextMSC1767: filename,
        kMXMessageContentKeyExtensibleFileMSC1767: @{
                kMXMessageContentKeyExtensibleFileSize: @(fileData.length),
                kMXMessageContentKeyExtensibleFileName: filename,
                kMXMessageContentKeyExtensibleFileURL: fakeMediaURI,
                kMXMessageContentKeyExtensibleFileMimeType: mimeType
        }.mutableCopy}.mutableCopy;

because mimeType is nil.

When mimeTypeis nil, it shoud fallback to application/octet-stream.

@NicolasBuquet
Copy link
Contributor Author

NicolasBuquet commented Sep 27, 2023

The fix is :

    // Prepare the message content for building an echo message
    NSMutableDictionary *msgContent = @{
        kMXMessageTypeKey: msgType,
        kMXMessageBodyKey: filename,
        @"url": fakeMediaURI,
        @"info": @{
            @"mimetype": (mimeType ?: @"application/octet-stream"),
                @"size": @(fileData.length)
        },
        kMXMessageContentKeyExtensibleTextMSC1767: filename,
        kMXMessageContentKeyExtensibleFileMSC1767: @{
                kMXMessageContentKeyExtensibleFileSize: @(fileData.length),
                kMXMessageContentKeyExtensibleFileName: filename,
                kMXMessageContentKeyExtensibleFileURL: fakeMediaURI,
                kMXMessageContentKeyExtensibleFileMimeType: (mimeType ?: @"@application/octet-stream"),
        }.mutableCopy}.mutableCopy;

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant