diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2022-02-07 10:06:52 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-07 10:06:52 -0500 |
commit | 314ca4c86d59777b98efe7da6c2a0e6ec3203b47 (patch) | |
tree | dbdcc84c5a97c626a0f1173466153de23ec3de19 /synapse/rest/media/v1 | |
parent | Clean up an indirect reference to the homeserver datastore (#11914) (diff) | |
download | synapse-314ca4c86d59777b98efe7da6c2a0e6ec3203b47.tar.xz |
Pass the proper type when uploading files. (#11927)
The Content-Length header should be treated as an int, not a string. This shouldn't have any user-facing change.
Diffstat (limited to 'synapse/rest/media/v1')
-rw-r--r-- | synapse/rest/media/v1/upload_resource.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/synapse/rest/media/v1/upload_resource.py b/synapse/rest/media/v1/upload_resource.py index 8162094cf6..fde28d08cb 100644 --- a/synapse/rest/media/v1/upload_resource.py +++ b/synapse/rest/media/v1/upload_resource.py @@ -49,10 +49,14 @@ class UploadResource(DirectServeJsonResource): async def _async_render_POST(self, request: SynapseRequest) -> None: requester = await self.auth.get_user_by_req(request) - content_length = request.getHeader("Content-Length") - if content_length is None: + raw_content_length = request.getHeader("Content-Length") + if raw_content_length is None: raise SynapseError(msg="Request must specify a Content-Length", code=400) - if int(content_length) > self.max_upload_size: + try: + content_length = int(raw_content_length) + except ValueError: + raise SynapseError(msg="Content-Length value is invalid", code=400) + if content_length > self.max_upload_size: raise SynapseError( msg="Upload request body is too large", code=413, @@ -66,7 +70,8 @@ class UploadResource(DirectServeJsonResource): upload_name: Optional[str] = upload_name_bytes.decode("utf8") except UnicodeDecodeError: raise SynapseError( - msg="Invalid UTF-8 filename parameter: %r" % (upload_name), code=400 + msg="Invalid UTF-8 filename parameter: %r" % (upload_name_bytes,), + code=400, ) # If the name is falsey (e.g. an empty byte string) ensure it is None. |