summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2018-12-03 11:47:48 +0100
committerAmber Brown <hawkowl@atleastfornow.net>2018-12-03 21:47:48 +1100
commitc03324294d3ff70f44db653ec0d9a6aa588883b4 (patch)
tree3cc73a0d6265e35a936e65feec503ef60078700e
parentNeilj/fix autojoin (#4223) (diff)
downloadsynapse-c03324294d3ff70f44db653ec0d9a6aa588883b4.tar.xz
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
-rw-r--r--changelog.d/4241.bugfix1
-rw-r--r--synapse/state/v1.py4
2 files changed, 4 insertions, 1 deletions
diff --git a/changelog.d/4241.bugfix b/changelog.d/4241.bugfix
new file mode 100644
index 0000000000..1158a5aa16
--- /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 70a981f4a2..19e091ce3b 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)