Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Discard an empty upload_name before persisting an uploaded file (#7905)
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot authored Sep 29, 2020
1 parent e154f7c commit c2bdf04
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/7905.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a longstanding bug when storing a media file with an empty `upload_name`.
7 changes: 4 additions & 3 deletions synapse/rest/media/v1/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,24 @@ def mark_recently_accessed(self, server_name, media_id):
async def create_content(
self,
media_type: str,
upload_name: str,
upload_name: Optional[str],
content: IO,
content_length: int,
auth_user: str,
) -> str:
"""Store uploaded content for a local user and return the mxc URL
Args:
media_type: The content type of the file
upload_name: The name of the file
media_type: The content type of the file.
upload_name: The name of the file, if provided.
content: A file like object that is the content to store
content_length: The length of the content
auth_user: The user_id of the uploader
Returns:
The mxc url of the stored content
"""

media_id = random_string(24)

file_info = FileInfo(server_name=None, file_id=media_id)
Expand Down
4 changes: 4 additions & 0 deletions synapse/rest/media/v1/upload_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ async def _async_render_POST(self, request):
msg="Invalid UTF-8 filename parameter: %r" % (upload_name), code=400
)

# If the name is falsey (e.g. an empty byte string) ensure it is None.
else:
upload_name = None

headers = request.requestHeaders

if headers.hasHeader(b"Content-Type"):
Expand Down

0 comments on commit c2bdf04

Please sign in to comment.