diff --git a/src/main/ssh/ssh-config-parser.test.ts b/src/main/ssh/ssh-config-parser.test.ts index 2b5cf6af34a..885ade1ff42 100644 --- a/src/main/ssh/ssh-config-parser.test.ts +++ b/src/main/ssh/ssh-config-parser.test.ts @@ -172,6 +172,18 @@ Host staging stage *.example.com ]) }) + it('parses generated configs with very large multi-alias Host lines', () => { + const aliases = Array.from({ length: 125_000 }, (_, index) => `host-${index}`) + const hosts = parseSshConfig(` +Host ${aliases.join(' ')} + HostName shared.example.com +`) + + expect(hosts).toHaveLength(aliases.length) + expect(hosts[0]).toEqual({ host: 'host-0', hostname: 'shared.example.com' }) + expect(hosts.at(-1)).toEqual({ host: 'host-124999', hostname: 'shared.example.com' }) + }) + it('applies identity agent settings to every concrete alias on a multi-pattern Host line', () => { const config = ` Host staging stage diff --git a/src/main/ssh/ssh-config-parser.ts b/src/main/ssh/ssh-config-parser.ts index 70b0cacdbe0..6d3d2a14dce 100644 --- a/src/main/ssh/ssh-config-parser.ts +++ b/src/main/ssh/ssh-config-parser.ts @@ -44,7 +44,7 @@ export function parseSshConfig(content: string): SshConfigHost[] { if (key === 'host') { if (current.length > 0) { - hosts.push(...current) + appendSshConfigHosts(hosts, current) } const patterns = splitHostPatterns(value) @@ -62,7 +62,7 @@ export function parseSshConfig(content: string): SshConfigHost[] { if (key === 'match') { if (current.length > 0) { - hosts.push(...current) + appendSshConfigHosts(hosts, current) } current = [] continue @@ -122,11 +122,19 @@ export function parseSshConfig(content: string): SshConfigHost[] { } if (current.length > 0) { - hosts.push(...current) + appendSshConfigHosts(hosts, current) } return hosts } +function appendSshConfigHosts(target: SshConfigHost[], entries: SshConfigHost[]): void { + // Why: generated SSH configs can contain very large Host alias lists; spreading + // those entries into push() can exceed V8's argument limit. + for (const entry of entries) { + target.push(entry) + } +} + function splitHostPatterns(input: string): string[] { const patterns: string[] = [] let current = ''