0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-06-14 08:38:24 +02:00

Fix event size checks (#13710)

This commit is contained in:
DeepBlueV7.X 2022-10-21 08:49:47 +00:00 committed by GitHub
parent cacda2d1f5
commit fab495a9e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

1
changelog.d/13710.bugfix Normal file
View file

@ -0,0 +1 @@
Fix a long-standing bug where Synapse would count codepoints instead of bytes when validating the size of some fields.

View file

@ -342,15 +342,15 @@ def check_state_dependent_auth_rules(
def _check_size_limits(event: "EventBase") -> None:
if len(event.user_id) > 255:
if len(event.user_id.encode("utf-8")) > 255:
raise EventSizeError("'user_id' too large")
if len(event.room_id) > 255:
if len(event.room_id.encode("utf-8")) > 255:
raise EventSizeError("'room_id' too large")
if event.is_state() and len(event.state_key) > 255:
if event.is_state() and len(event.state_key.encode("utf-8")) > 255:
raise EventSizeError("'state_key' too large")
if len(event.type) > 255:
if len(event.type.encode("utf-8")) > 255:
raise EventSizeError("'type' too large")
if len(event.event_id) > 255:
if len(event.event_id.encode("utf-8")) > 255:
raise EventSizeError("'event_id' too large")
if len(encode_canonical_json(event.get_pdu_json())) > MAX_PDU_SIZE:
raise EventSizeError("event too large")