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

Commit 2b467d0

Browse files
authored
Properly raise an exception when the body exceeds the max size. (#9145)
...instead of just creating the exception object and doing nothing with it.
1 parent 02070c6 commit 2b467d0

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

changelog.d/9145.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix "UnboundLocalError: local variable 'length' referenced before assignment" errors when the response body exceeds the expected size. This bug was introduced in v1.25.0.

synapse/http/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ async def get_file(
724724
read_body_with_max_size(response, output_stream, max_size)
725725
)
726726
except BodyExceededMaxSize:
727-
SynapseError(
727+
raise SynapseError(
728728
502,
729729
"Requested file is too large > %r bytes" % (max_size,),
730730
Codes.TOO_LARGE,

synapse/http/matrixfederationclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ async def get_file(
996996
logger.warning(
997997
"{%s} [%s] %s", request.txn_id, request.destination, msg,
998998
)
999-
SynapseError(502, msg, Codes.TOO_LARGE)
999+
raise SynapseError(502, msg, Codes.TOO_LARGE)
10001000
except Exception as e:
10011001
logger.warning(
10021002
"{%s} [%s] Error reading response: %s",

0 commit comments

Comments
 (0)