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

Commit

Permalink
Workaround for non-ascii event ids (#4241)
Browse files Browse the repository at this point in the history
It turns out that we accept events with non-ascii IDs, which would later cause
an explosion during state res.

Fixes #4226
  • Loading branch information
richvdh authored and hawkowl committed Dec 3, 2018
1 parent 7039ece commit c033242
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/4241.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix exception caused by non-ascii event IDs
4 changes: 3 additions & 1 deletion synapse/state/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ def _resolve_normal_events(events, auth_events):

def _ordered_events(events):
def key_func(e):
return -int(e.depth), hashlib.sha1(e.event_id.encode('ascii')).hexdigest()
# we have to use utf-8 rather than ascii here because it turns out we allow
# people to send us events with non-ascii event IDs :/
return -int(e.depth), hashlib.sha1(e.event_id.encode('utf-8')).hexdigest()

return sorted(events, key=key_func)

0 comments on commit c033242

Please sign in to comment.