From 4f0f2e8c16a5bd50cb3f7ecc4638e39ee2dead20 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Mon, 29 Jul 2019 15:27:32 +0100 Subject: [PATCH 1/2] Fix issues with recursive tombstones --- src/client.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/client.js b/src/client.js index df673885c0e..94068d37e3f 100644 --- a/src/client.js +++ b/src/client.js @@ -62,6 +62,7 @@ Promise.config({warnings: false}); const SCROLLBACK_DELAY_MS = 3000; const CRYPTO_ENABLED = isCryptoAvailable(); const CAPABILITIES_CACHE_MS = 21600000; // 6 hours - an arbitrary value +const MAX_TOMBSTONE_HISTORY = 30; function keysFromRecoverySession(sessions, decryptionKey, roomId) { const keys = []; @@ -2369,6 +2370,7 @@ MatrixClient.prototype.getRoomUpgradeHistory = function(roomId, verifyLinks=fals while (tombstoneEvent) { const refRoom = this.getRoom(tombstoneEvent.getContent()['replacement_room']); if (!refRoom) break; // end of the chain + if (refRoom.roomId === currentRoom.roomId) break; // Tombstone is referencing it's own room if (verifyLinks) { createEvent = refRoom.currentState.getStateEvents("m.room.create", ""); @@ -2380,6 +2382,12 @@ MatrixClient.prototype.getRoomUpgradeHistory = function(roomId, verifyLinks=fals // Push to the end because we're looking forwards upgradeHistory.push(refRoom); + const roomIds = upgradeHistory.map((ref) => ref.roomId); + if ((new Set(roomIds)).size < roomIds.length) { + // The last room added to the list introduced a previous roomId + // To avoid recursion, return the last rooms - 1 + return upgradeHistory.slice(0, upgradeHistory.length - 1); + } // Set the current room to the reference room so we know where we're at currentRoom = refRoom; From c9bf61c38749164ed956e8aad37da82bf1a0bc5a Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Mon, 29 Jul 2019 15:29:18 +0100 Subject: [PATCH 2/2] Simplify Set --- src/client.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/client.js b/src/client.js index 94068d37e3f..af01a6d325e 100644 --- a/src/client.js +++ b/src/client.js @@ -62,7 +62,6 @@ Promise.config({warnings: false}); const SCROLLBACK_DELAY_MS = 3000; const CRYPTO_ENABLED = isCryptoAvailable(); const CAPABILITIES_CACHE_MS = 21600000; // 6 hours - an arbitrary value -const MAX_TOMBSTONE_HISTORY = 30; function keysFromRecoverySession(sessions, decryptionKey, roomId) { const keys = []; @@ -2382,8 +2381,8 @@ MatrixClient.prototype.getRoomUpgradeHistory = function(roomId, verifyLinks=fals // Push to the end because we're looking forwards upgradeHistory.push(refRoom); - const roomIds = upgradeHistory.map((ref) => ref.roomId); - if ((new Set(roomIds)).size < roomIds.length) { + const roomIds = new Set(upgradeHistory.map((ref) => ref.roomId)); + if (roomIds.size < upgradeHistory.length) { // The last room added to the list introduced a previous roomId // To avoid recursion, return the last rooms - 1 return upgradeHistory.slice(0, upgradeHistory.length - 1);