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

Fix event size checks #13710

Merged
merged 3 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/13710.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long standing bug, where Synapse would count codepoints instead of bytes when validating the size of some fields.
reivilibre marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 5 additions & 5 deletions synapse/event_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,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")
Expand Down