Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): bound legacy manifest reads before scanning
Yuewei-LL4e5e8936aa4a
diff --git a/apps/desktop/src/main/__tests__/ownerNamespaceMigration.test.ts b/apps/desktop/src/main/__tests__/ownerNamespaceMigration.test.tsindex dfbf33ed3d..684c672812 100644--- a/apps/desktop/src/main/__tests__/ownerNamespaceMigration.test.ts+++ b/apps/desktop/src/main/__tests__/ownerNamespaceMigration.test.ts@@ -2209,13 +2209,18 @@ describe('legacy Ghost plugin recovery', () => {const ownerId = 'cloud-a';await writeGhostDir(root, 'cindy-brain', 'unreadable-manifest');const manifestPath = path.join(root, 'cindy-brain', 'unreadable-manifest', 'ghost.json');- const originalReadFile = fsSync.readFileSync.bind(fsSync);- const readFileSpy = vi.spyOn(fsSync, 'readFileSync').mockImplementation((file, options) => {- if (path.resolve(String(file)) === path.resolve(manifestPath)) {- throw Object.assign(new Error('manifest locked'), { code: 'EACCES' });- }- return originalReadFile(file as never, options as never) as never;- });+ const boundedModule = await import('../utils/readBoundedFile.js');+ const originalNoFollowSync = boundedModule.readBoundedFileNoFollowSync;+ const noFollowSpy = vi+ .spyOn(boundedModule, 'readBoundedFileNoFollowSync')+ .mockImplementation(+ (file: string, maxBytes?: number, options?: { containWithin?: string; nonBlocking?: boolean }) => {+ if (path.resolve(String(file)) === path.resolve(manifestPath)) {+ throw Object.assign(new Error('manifest locked'), { code: 'EACCES' });+ }+ return originalNoFollowSync(file, maxBytes!, options!);+ },+ );try {expect(getLegacyGhostRecoveryStatus(@@ -2239,7 +2244,7 @@ describe('legacy Ghost plugin recovery', () => {deferredReason: 'legacy-discovery-incomplete',});} finally {- readFileSpy.mockRestore();+ noFollowSpy.mockRestore();}await expect(fs.access(manifestPath)).resolves.toBeUndefined();await expect(diff --git a/apps/desktop/src/main/ownerNamespaceMigration.ts b/apps/desktop/src/main/ownerNamespaceMigration.tsindex ad114c29fb..fae7c11087 100644--- a/apps/desktop/src/main/ownerNamespaceMigration.ts+++ b/apps/desktop/src/main/ownerNamespaceMigration.ts@@ -19,7 +19,7 @@ import {} from '../shared/legacyGhostRecovery.js';import { readLegacyGhostApprovalProjection } from './cindy-brain/GhostManager.js';import { withGhostInstallLock } from './cindy-brain/ghostInstallLock.js';-import { readBoundedFileNoFollow, readBoundedFileNoFollowSync } from './utils/readBoundedFile.js';+import { readBoundedFileNoFollow, readBoundedFileNoFollowSync, GHOST_MANIFEST_MAX_BYTES } from './utils/readBoundedFile.js';const CLAIM_MARKER = '.owner-namespace-claim-v1.json';const LEGACY_GHOST_RECOVERY_MARKER = '.legacy-ghost-recovery-v1.json';@@ -824,15 +824,19 @@ function readLegacyGhostManifest(dir: string,expectedId: string,): LegacyGhostManifestRead {- let text: string;+ const manifestPath = path.join(dir, GHOST_MANIFEST_FILE);+ let bytes: Buffer | null;try {- text = fsSync.readFileSync(path.join(dir, GHOST_MANIFEST_FILE), 'utf-8');+ bytes = readBoundedFileNoFollowSync(manifestPath, GHOST_MANIFEST_MAX_BYTES, {+ containWithin: dir,+ });} catch (error) {return isMissing(error) ? { kind: 'invalid' } : { kind: 'deferred' };}+ if (!bytes) return { kind: 'invalid' };let raw: unknown;try {- raw = JSON.parse(text);+ raw = JSON.parse(bytes.toString('utf-8'));} catch {return { kind: 'invalid' };}