Skip to content

Commit 945bf8a

Browse files
committed
fix: add root guard to dirname loops in extension discovery
Add filesystem root detection to two directory-traversal loops in `src/extension/extension.ts` that hang indefinitely when processing files at the filesystem root (e.g. `/mermaid.qmd` in Docker containers with `WORKDIR /`). `dirname("/")` returns `"/"`, so loops without a root guard never terminate. Apply the same `nextDir === dir` pattern already used in `src/project/project-context.ts`. Closes #14254
1 parent 64a2120 commit 945bf8a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/extension/extension.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ export function inputExtensionDirs(input?: string, projectDir?: string) {
563563
if (extensionPath) {
564564
extensionDirectories.push(extensionPath);
565565
}
566-
currentDir = dirname(currentDir);
566+
const nextDir = dirname(currentDir);
567+
if (nextDir === currentDir) break;
568+
currentDir = nextDir;
567569
} while (isSubdir(projectDir, currentDir) || projectDir === currentDir);
568570
return extensionDirectories;
569571
} else if (input) {
@@ -878,7 +880,12 @@ async function readExtension(
878880
let projectDir = extensionDir, last;
879881
do {
880882
last = basename(projectDir);
881-
projectDir = dirname(projectDir);
883+
const nextDir = dirname(projectDir);
884+
if (nextDir === projectDir) {
885+
projectDir = "";
886+
break;
887+
}
888+
projectDir = nextDir;
882889
} while (projectDir && last !== "_extensions");
883890
if (projectDir) {
884891
(object.project as Record<string, unknown>)[key] = relative(

0 commit comments

Comments
 (0)