From c03324294d3ff70f44db653ec0d9a6aa588883b4 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Mon, 3 Dec 2018 11:47:48 +0100 Subject: [PATCH] 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 --- changelog.d/4241.bugfix | 1 + synapse/state/v1.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelog.d/4241.bugfix diff --git a/changelog.d/4241.bugfix b/changelog.d/4241.bugfix new file mode 100644 index 000000000..1158a5aa1 --- /dev/null +++ b/changelog.d/4241.bugfix @@ -0,0 +1 @@ +Fix exception caused by non-ascii event IDs diff --git a/synapse/state/v1.py b/synapse/state/v1.py index 70a981f4a..19e091ce3 100644 --- a/synapse/state/v1.py +++ b/synapse/state/v1.py @@ -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)