Skip to content

Commit

Permalink
Guard against infinite loop on bad input in ChangeSet.map
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Jun 25, 2024
1 parent 7a94b24 commit fe9667c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fe9667c

Please sign in to comment.