Git - guard against undefined paths in parseGitChangesRaw (#287615)#314614
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
Git - guard against undefined paths in parseGitChangesRaw (#287615)#314614yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the Git extension’s parseGitChangesRaw parser (used for git diff --raw --numstat -z) to avoid throwing when the null-delimited segment stream is unexpectedly truncated, which was surfacing as Uri.file(...) receiving undefined and breaking commit history/multi-file diff rendering.
Changes:
- Add defensive guards to stop parsing when a
--rawfile path segment is missing. - Add defensive guards to stop parsing when a
--numstatrename “new path” segment is missing.
Comment on lines
1138
to
+1143
| // Parse --raw output | ||
| const [, , , , change] = segment.split(' '); | ||
| const filePath = segments[index++]; | ||
| if (!filePath) { | ||
| break; | ||
| } |
Comment on lines
+1192
to
1196
| break; | ||
| } | ||
| numstatPath = path.isAbsolute(renamePath) ? renamePath : path.join(repositoryRoot, renamePath); | ||
| } else { | ||
| numstatPath = path.isAbsolute(filePath) ? filePath : path.join(repositoryRoot, filePath); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@
Fixes #287615
Root cause
parseGitChangesRawinextensions/git/src/git.tsparses the null-delimited output ofgit diff --raw --numstat -z. The parser advances through the segments array using a manualindex++counter and reads file paths viasegments[index++]in two places:--rawbranch: the file path that immediately follows the metadata segment.--numstatrename branch: the new path that follows the empty filename and the skipped old path.Neither read was guarded for the case where
indexruns past the end ofsegments(or yields an empty/undefined value). When that happens, the resultingfilePathisundefined, and the subsequentUri.file(...)call throws:This bubbles up through
GitHistoryProvider.provideHistoryItemChangesand is logged byextHostSCM.tsasExtHostSCM#$provideHistoryItemChanges The "path" argument must be of type string. Received undefined, leaving the multi-file diff editor with no listed files.Fix
Add a defensive
if (!filePath) break;/if (!renamePath) break;guard in both branches, mirroring the existing guard already present for the renamenewPathsegment a few lines below. If the segment stream is unexpectedly truncated, parsing stops cleanly instead of crashing the provider call.Narrow change: 6 added lines in one file, no behavior change for well-formed input.
Test plan
path must be of type stringerror in Extension Host log; changed files render in the multi-file diff editor.@