From 7abe279b4a7e132ddb0c0fd32bb389a4ee2acb2f Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Sun, 16 Jan 2022 15:08:14 +0100 Subject: [PATCH] #2631 Adding safeguard to the while loops --- src/diagrams/git/gitGraphAst.js | 4 +++- src/diagrams/git/gitGraphRenderer.js | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/diagrams/git/gitGraphAst.js b/src/diagrams/git/gitGraphAst.js index 8bb882ac8..d335e3747 100644 --- a/src/diagrams/git/gitGraphAst.js +++ b/src/diagrams/git/gitGraphAst.js @@ -17,7 +17,9 @@ function getId() { */ function isfastforwardable(currentCommit, otherCommit) { log.debug('Entering isfastforwardable:', currentCommit.id, otherCommit.id); - while (currentCommit.seq <= otherCommit.seq && currentCommit !== otherCommit) { + let cnt = 0; + while (currentCommit.seq <= otherCommit.seq && currentCommit !== otherCommit && cnt < 1000) { + cnt++; // only if other branch has more commits if (otherCommit.parent == null) break; if (Array.isArray(otherCommit.parent)) { diff --git a/src/diagrams/git/gitGraphRenderer.js b/src/diagrams/git/gitGraphRenderer.js index 341eeea67..e9da5faa1 100644 --- a/src/diagrams/git/gitGraphRenderer.js +++ b/src/diagrams/git/gitGraphRenderer.js @@ -227,7 +227,9 @@ function renderCommitHistory(svg, commitid, branches, direction) { let commit; const numCommits = Object.keys(allCommitsDict).length; if (typeof commitid === 'string') { + let cnt = 0; do { + cnt++; commit = allCommitsDict[commitid]; log.debug('in renderCommitHistory', commit.id, commit.seq); if (svg.select('#node-' + commitid).size() > 0) { @@ -293,7 +295,7 @@ function renderCommitHistory(svg, commitid, branches, direction) { .text(', ' + commit.message); } commitid = commit.parent; - } while (commitid && allCommitsDict[commitid]); + } while (commitid && allCommitsDict[commitid] && cnt < 1000); } if (Array.isArray(commitid)) { @@ -313,7 +315,9 @@ function renderCommitHistory(svg, commitid, branches, direction) { */ function renderLines(svg, commit, direction, branchColor) { branchColor = branchColor || 0; - while (commit.seq > 0 && !commit.lineDrawn) { + let cnt = 0; + while (commit.seq > 0 && !commit.lineDrawn && cnt < 1000) { + cnt++; if (typeof commit.parent === 'string') { svgDrawLineForCommits(svg, commit.id, commit.parent, direction, branchColor); commit.lineDrawn = true;