fix(media): Validate preview image downloads #2308
No reviewers
Labels
No labels
Abandoned
Blocked
Bug
Changelog
Added
Changelog
Missing
Changelog
None
Cherry-picking
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Merge
Merge/Manual
Merge/Squash
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
bob the builder
No milestone
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
continuwuation/continuwuity!2308
Loading…
Reference in a new issue
No description provided.
Delete branch "eleboucher/continuwuity:fix/url-preview-images"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fix preview images by storing the correct MIME type, rejecting failed or invalid downloads, and limiting decoding memory and concurrency.
Fixes: #2304
Pull request checklist:
mainbranch, and the branch is named something other thanmain.myself, if applicable. This includes ensuring code compiles.
1148655a185fb8dd239f@ -63,2 +65,4 @@Ok(Arc::new(Self {url_preview_mutex: MutexMap::new(),#[cfg(feature = "url_preview")]url_preview_image_semaphore: Arc::new(tokio::sync::Semaphore::new(2)),this semaphore seems like an arbitrary performance limitation
@ -159,0 +182,4 @@err!(Request(Unknown("Downloaded file is not a supported image")))})?.to_mime_type();let decoded = reader.decode().map_err(|error| {why are we decoding it when the response is already returning a stream of data? this seems like a waste of compute
@ -177,3 +201,1 @@preview_data.image_width = width;preview_data.image_height = height;}preview_data.image_width = Some(width);We shouldn't be unconditionally overriding data returned by the remote