Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[MM-60232] Fix a crash in Linux when trying to create a thumbnail from an image #3147

Merged
merged 4 commits into from
Sep 19, 2024

Conversation

devinbinnie
Copy link
Member

@devinbinnie devinbinnie commented Sep 19, 2024

Summary

When we made the fix to disallow the file: protocol, we started using createThumbnailFromPath to process images. Unfortunately, this function is simply not defined on Linux, causing a crash.

This PR falls back to using the createFromPath function for Linux only, which creates a full version of the image. I've capped the image size to use at 1MB so that we don't inflate the memory usage of the downloads dropdown too much.

Ticket Link

https://mattermost.atlassian.net/browse/MM-60232
Closes #3129

Fix a crash in Linux when trying to create a thumbnail from an image

@devinbinnie devinbinnie added the 2: Dev Review Requires review by a core committer label Sep 19, 2024
@devinbinnie devinbinnie added this to the v5.9.0 milestone Sep 19, 2024
// Linux doesn't support the thumbnail creation so we have to use the base function
if (process.platform === 'linux') {
// We also will cap this at 1MB so as to not inflate the memory usage of the downloads dropdown
if (item.getReceivedBytes() < 1000000) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please clarify

to not inflate the memory usage of the downloads

Does it mean if image size is greater than 1mb we wont show the preview in the download dropdown

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. This is a bit of pre-emptive safety, but I did notice that if you do have a really large image stored in the JSON (like I had before) it will slow down the app significantly, so I want to avoid that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is for images only dont we have access to preview url of the image?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not anymore, we can't use the file:/// protocol which would facilitate that. And we don't want to open up mattermost-desktop: to arbitrary files, or else security becomes a concern.

I'd be up for trying to figure out a better solution in the future, but this works for now.

@devinbinnie devinbinnie added 4: Reviews Complete All reviewers have approved the pull request CherryPick/Approved Meant for the quality or patch release tracked in the milestone and removed 2: Dev Review Requires review by a core committer labels Sep 19, 2024
@devinbinnie devinbinnie merged commit b4eeabb into master Sep 19, 2024
19 of 20 checks passed
@devinbinnie devinbinnie deleted the MM-60232 branch September 19, 2024 19:00
@devinbinnie
Copy link
Member Author

/cherry-pick release-5.9

@mattermost-build
Copy link
Contributor

Cherry pick is scheduled.

mattermost-build pushed a commit that referenced this pull request Sep 19, 2024
…m an image (#3147)

* [MM-60232] Fix a crash in Linux when trying to create a thumbnail from an image

* Fix lint

* Cap at 1MB

* Fix crash again

(cherry picked from commit b4eeabb)
@mattermost-build mattermost-build added CherryPick/Done Successfully cherry-picked to the quality or patch release tracked in the milestone and removed CherryPick/Approved Meant for the quality or patch release tracked in the milestone labels Sep 19, 2024
devinbinnie added a commit that referenced this pull request Sep 19, 2024
…m an image (#3147) (#3149)

* [MM-60232] Fix a crash in Linux when trying to create a thumbnail from an image

* Fix lint

* Cap at 1MB

* Fix crash again

(cherry picked from commit b4eeabb)

Co-authored-by: Devin Binnie <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request CherryPick/Done Successfully cherry-picked to the quality or patch release tracked in the milestone release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Crash]: TypeError: s.nativeImage.createThumbnailFromPath is not a function
5 participants