Workaround for non-ascii event ids (#4241)

It turns out that we accept events with non-ascii IDs, which would later cause
an explosion during state res.

Fixes #4226
This commit is contained in:
Richard van der Hoff 2018-12-03 11:47:48 +01:00 committed by Amber Brown
parent 7039ece8fb
commit c03324294d
2 changed files with 4 additions and 1 deletions

1
changelog.d/4241.bugfix Normal file
View File

@ -0,0 +1 @@
Fix exception caused by non-ascii event IDs

View File

@ -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)