From 2e6f93af723ce29b229b095a6d11b0981c4752c6 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 16 Dec 2024 10:58:46 +0100 Subject: [PATCH 1/3] Cap output from git at string max length Include operation name when maxBuffer is exceeded --- app/src/lib/git/core.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/lib/git/core.ts b/app/src/lib/git/core.ts index c366fe5e530..149d937cde2 100644 --- a/app/src/lib/git/core.ts +++ b/app/src/lib/git/core.ts @@ -16,6 +16,7 @@ import { merge } from '../merge' import { withTrampolineEnv } from '../trampoline/trampoline-environment' import { createTailStream } from './create-tail-stream' import { createTerminalStream } from '../create-terminal-stream' +import { kStringMaxLength } from 'buffer' export const coerceToString = ( value: string | Buffer, @@ -207,6 +208,7 @@ export async function git( const defaultOptions: IGitExecutionOptions = { successExitCodes: new Set([0]), expectedErrors: new Set(), + maxBuffer: options?.encoding === 'buffer' ? Infinity : kStringMaxLength, } const opts = { ...defaultOptions, ...options } @@ -259,6 +261,21 @@ export async function git( throw new Error(`Failed to execute ${name}: ${err.code}`) } + if (isMaxBufferExceededError(err)) { + throw new ExecError( + `${err.message} for ${name}`, + err.stdout, + err.stderr, + // Dugite stores the original Node error in the cause property, by + // passing that along we ensure that all we're doing here is + // changing the error message (and capping the stack but that's + // okay since we know exactly where this error is coming from). + // The null coalescing here is a safety net in case dugite's + // behavior changes from underneath us. + err.cause ?? err + ).message + } + throw err }) From afc147e82c626be53692e2a4528d45dfc468fc33 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 16 Dec 2024 14:34:08 +0100 Subject: [PATCH 2/3] Bump version --- app/package.json | 2 +- changelog.json | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/package.json b/app/package.json index c3f7a76ff1e..4d19dd51526 100644 --- a/app/package.json +++ b/app/package.json @@ -3,7 +3,7 @@ "productName": "GitHub Desktop", "bundleID": "com.github.GitHubClient", "companyName": "GitHub, Inc.", - "version": "3.4.10", + "version": "3.4.11", "main": "./main.js", "repository": { "type": "git", diff --git a/changelog.json b/changelog.json index d5c86b935ca..5f706091a1d 100644 --- a/changelog.json +++ b/changelog.json @@ -1,5 +1,8 @@ { "releases": { + "3.4.11": [ + "[Fixed] Prevent crash due to excessively long Git output - #19724" + ], "3.4.10": [ "[Added] Add a banner for communicating when prioritized updates exist - #19655", "[Added] Add \"View Pull Request on GitHub\" Option to the Checked-Out Branch Button and Pull Requests List - #19453. Thanks @DylanDevelops!", From 9db0c06fa01690a8c8a6a3c456ed7660475b89a6 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Mon, 16 Dec 2024 14:46:55 +0100 Subject: [PATCH 3/3] Face, meet palm --- app/src/lib/git/core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/lib/git/core.ts b/app/src/lib/git/core.ts index 149d937cde2..ace69eb88da 100644 --- a/app/src/lib/git/core.ts +++ b/app/src/lib/git/core.ts @@ -273,7 +273,7 @@ export async function git( // The null coalescing here is a safety net in case dugite's // behavior changes from underneath us. err.cause ?? err - ).message + ) } throw err