缺陷 / 高 / 工具系统
electron/harness/tools/built-in/filesystem.ts (SearchFilesTool)
electron/harness/tools/built-in/filesystem.ts
SearchFilesTool.walkDir 递归遍历目录,未限制:
async walkDir(root: string, callback: (path) => void, options: { maxDepth: number = 20; maxFiles: number = 100_000; followSymlinks: boolean = false; } = {}) { const visited = new Set<string>(); let fileCount = 0; async function walk(current: string, depth: number) { if (depth > options.maxDepth || fileCount > options.maxFiles) return; const real = realpathSync(current); if (visited.has(real)) return; // 防止循环 visited.add(real); const entries = await readdir(current, { withFileTypes: true }); for (const entry of entries) { if (++fileCount > options.maxFiles) break; const fullPath = join(current, entry.name); if (entry.isDirectory()) { if (options.followSymlinks || !entry.isSymbolicLink()) { await walk(fullPath, depth + 1); } } else { callback(fullPath); } } } await walk(root, 0); }
同时考虑用 worker_threads 避免阻塞主进程。
No dependencies set.
The note is not visible to the blocked user.
问题类型
缺陷 / 高 / 工具系统
文件位置
electron/harness/tools/built-in/filesystem.ts(SearchFilesTool)问题描述
SearchFilesTool.walkDir 递归遍历目录,未限制:
影响
建议修复
同时考虑用 worker_threads 避免阻塞主进程。