From c07d383b73adaa3388cf05054fa1ac289820ffef Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 2 Dec 2020 10:58:10 -0500 Subject: [PATCH 1/2] Do not error if the content-length is not provided. --- changelog.d/8862.bugfix | 1 + synapse/rest/media/v1/upload_resource.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog.d/8862.bugfix diff --git a/changelog.d/8862.bugfix b/changelog.d/8862.bugfix new file mode 100644 index 000000000000..2317277fdab5 --- /dev/null +++ b/changelog.d/8862.bugfix @@ -0,0 +1 @@ +Fix a longstanding bug if the `Content-Length` header was not provided to the upload media resource. diff --git a/synapse/rest/media/v1/upload_resource.py b/synapse/rest/media/v1/upload_resource.py index d76f7389e101..42febc9afcf6 100644 --- a/synapse/rest/media/v1/upload_resource.py +++ b/synapse/rest/media/v1/upload_resource.py @@ -44,7 +44,7 @@ async def _async_render_POST(self, request): requester = await self.auth.get_user_by_req(request) # TODO: The checks here are a bit late. The content will have # already been uploaded to a tmp file at this point - content_length = request.getHeader(b"Content-Length").decode("ascii") + content_length = request.getHeader("Content-Length") if content_length is None: raise SynapseError(msg="Request must specify a Content-Length", code=400) if int(content_length) > self.max_upload_size: From a5e9eff9e8fd88bcedbfefa0d2171080d2ad6922 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Fri, 4 Dec 2020 09:57:34 -0500 Subject: [PATCH 2/2] Clarify changelog. --- changelog.d/8862.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/8862.bugfix b/changelog.d/8862.bugfix index 2317277fdab5..bdbd633f7234 100644 --- a/changelog.d/8862.bugfix +++ b/changelog.d/8862.bugfix @@ -1 +1 @@ -Fix a longstanding bug if the `Content-Length` header was not provided to the upload media resource. +Fix a longstanding bug where a 500 error would be returned if the `Content-Length` header was not provided to the upload media resource.