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

Commit

Permalink
Fix bug which caused failure on join with malformed membership events (
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh authored Sep 23, 2020
1 parent cbabb31 commit 302dc89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/8385.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug which could cause errors in rooms with malformed membership events, on servers using sqlite.
10 changes: 7 additions & 3 deletions synapse/storage/databases/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import itertools
import logging
from collections import OrderedDict, namedtuple
from typing import TYPE_CHECKING, Dict, Iterable, List, Set, Tuple
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Set, Tuple

import attr
from prometheus_client import Counter
Expand Down Expand Up @@ -1108,6 +1108,10 @@ def _store_event_reference_hashes_txn(self, txn, events):
def _store_room_members_txn(self, txn, events, backfilled):
"""Store a room member in the database.
"""

def str_or_none(val: Any) -> Optional[str]:
return val if isinstance(val, str) else None

self.db_pool.simple_insert_many_txn(
txn,
table="room_memberships",
Expand All @@ -1118,8 +1122,8 @@ def _store_room_members_txn(self, txn, events, backfilled):
"sender": event.user_id,
"room_id": event.room_id,
"membership": event.membership,
"display_name": event.content.get("displayname", None),
"avatar_url": event.content.get("avatar_url", None),
"display_name": str_or_none(event.content.get("displayname")),
"avatar_url": str_or_none(event.content.get("avatar_url")),
}
for event in events
],
Expand Down

0 comments on commit 302dc89

Please sign in to comment.