From 64b8e014444982c3091340d989d5d9bf92c314cb Mon Sep 17 00:00:00 2001 From: Sorunome Date: Thu, 10 Sep 2020 11:24:37 +0200 Subject: [PATCH] fix: Handle duplicate indexes properly --- lib/encryption/encryption.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/encryption/encryption.dart b/lib/encryption/encryption.dart index f6f3a3c..b56dd1e 100644 --- a/lib/encryption/encryption.dart +++ b/lib/encryption/encryption.dart @@ -148,6 +148,13 @@ class Encryption { // TODO: maybe clear outbound session, if it is ours throw (DecryptError.CHANNEL_CORRUPTED); } + final existingIndex = inboundGroupSession.indexes.entries.firstWhere( + (e) => e.value == decryptResult.message_index, + orElse: () => null); + if (existingIndex != null && existingIndex.key != messageIndexKey) { + // TODO: maybe clear outbound session, if it is ours + throw (DecryptError.CHANNEL_CORRUPTED); + } inboundGroupSession.indexes[messageIndexKey] = decryptResult.message_index; if (!haveIndex) {