From fe9667cc6a279cdb96d82891840b2c414e881314 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 25 Jun 2024 09:44:35 +0200 Subject: [PATCH] Guard against infinite loop on bad input in ChangeSet.map --- src/change.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/change.ts b/src/change.ts index 3b6fd4c..9155a41 100644 --- a/src/change.ts +++ b/src/change.ts @@ -435,7 +435,9 @@ function mapSet(setA: ChangeDesc, setB: ChangeDesc, before: boolean, mkSet = fal // content has been inserted already, and refers to the section // index. for (let inserted = -1;;) { - if (a.ins == -1 && b.ins == -1) { + if (a.done && b.len || b.done && a.len) { + throw new Error("Mismatched change set lengths") + } else if (a.ins == -1 && b.ins == -1) { // Move across ranges skipped by both sets. let len = Math.min(a.len, b.len) addSection(sections, len, -1)