From fc247f3cf772e8681c24b05563dad6934ce2a5ed Mon Sep 17 00:00:00 2001 From: Sean Quah Date: Thu, 8 Sep 2022 13:56:18 +0100 Subject: [PATCH] Avoid raising errors due to malformed IDs in `get_current_hosts_in_room` Handle malformed user IDs with no colons in `get_current_hosts_in_room`. It's not currently possible for a malformed user ID to join a room, so this error would never be hit. Signed-off-by: Sean Quah --- changelog.d/13748.misc | 1 + synapse/storage/databases/main/roommember.py | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 changelog.d/13748.misc diff --git a/changelog.d/13748.misc b/changelog.d/13748.misc new file mode 100644 index 000000000000..2f419bb659a1 --- /dev/null +++ b/changelog.d/13748.misc @@ -0,0 +1 @@ +Avoid raising an error due to malformed user IDs in `get_current_hosts_in_room`. Malformed user IDs cannot currently join a room, so this error would not be hit. diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py index a77e49dc66e3..53a476036228 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py @@ -1044,6 +1044,8 @@ async def get_current_hosts_in_room(self, room_id: str) -> List[str]: # We use a `Set` just for fast lookups domain_set: Set[str] = set() for u in users: + if ":" not in u: + continue domain = get_domain_from_id(u) if domain not in domain_set: domain_set.add(domain) @@ -1071,6 +1073,7 @@ def get_current_hosts_in_room_txn(txn: LoggingTransaction) -> List[str]: c.type = 'm.room.member' AND c.membership = 'join' AND c.room_id = ? + AND server_domain IS NOT NULL /* Group all state events from the same domain into their own buckets (groups) */ GROUP BY server_domain /* Sorted by lowest depth first */