Repository navigation
fix(git): fence buffered WSL login-shell reads - #15060
Conversation
0e82843 to
fd6b9bf
Compare
0e92372 to
4a8d8ea
Compare
6706876 to
6f46fe5
Compare
Two git paths force the login shell unconditionally and buffer its whole stdout, so the distro's rc banner lands in front of the payload: - gitExecFileAsyncBuffer backs `git show :<path>` blob reads and hands the bytes straight to the diff/blob viewer, so the banner is prepended to displayed file content. - buildNetworkSshPolicyEnv probes `core.sshCommand` and treats any non-empty answer as a user-configured wrapper. A banner reads as configured, so the code skips the `ssh -o BatchMode=yes` fallback and silently disarms the guard that keeps non-interactive SSH from hanging on a prompt. Fencing is opt-in per call site rather than applied to the login-shell branch as a whole: streaming consumers (`git grep`, `ls-files -z`) parse records as they arrive, so an opening marker would be glued onto their first record. Only these two, both buffered by construction, opt in. Blob content can be binary, so the payload is sliced out of the raw bytes; decoding to find the fence would corrupt it. The markers are exposed on the captured command because the shared module is bundled for the renderer and cannot reference Buffer. Note this path is not a rare fallback: `preferWslDirectGit` is only set by gitStatusReadOptionsForWorktree, so every other WSL-routed git call takes the login shell on every invocation.
4a8d8ea to
d79a008
Compare
Satisfies the code-quality rule that flags filter-then-index.
d79a008 to
bdc65a0
Compare
📝 WalkthroughWalkthroughWSL login-shell command resolution can wrap stdout with generated fence markers and return capture metadata. Git command resolution propagates this option. SSH configuration probing strips the markers before parsing Merge Risk: 🟡 Moderate · up to The change improves buffered WSL Git reads, but the current implementation can select an echoed shell marker instead of the real payload and return incorrect file contents, including corrupted binary data. This correctness issue should be fixed before merging. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a41f5d22-c9b2-4234-82d9-f38d91a95378
📒 Files selected for processing (3)
src/main/git/runner-wsl-login-shell-capture.test.tssrc/main/git/runner.tssrc/shared/wsl-login-shell-command.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 7 remain after this review.
| afterEach(() => { | ||
| Object.defineProperty(process, 'platform', { configurable: true, value: process.platform }) | ||
| resetWslGitReadEnvironmentForTests() | ||
| }) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Restore the original platform value.
Line 63 reads process.platform after beforeEach sets it to win32. The cleanup writes win32 again. Store the original value before the hooks, then restore that value.
Proposed fix
+const originalPlatform = process.platform
+
// ...
afterEach(() => {
- Object.defineProperty(process, 'platform', { configurable: true, value: process.platform })
+ Object.defineProperty(process, 'platform', { configurable: true, value: originalPlatform })📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| afterEach(() => { | |
| Object.defineProperty(process, 'platform', { configurable: true, value: process.platform }) | |
| resetWslGitReadEnvironmentForTests() | |
| }) | |
| const originalPlatform = process.platform | |
| afterEach(() => { | |
| Object.defineProperty(process, 'platform', { configurable: true, value: originalPlatform }) | |
| resetWslGitReadEnvironmentForTests() | |
| }) |
| const beginIndex = stdout.indexOf(captured.beginMarker, 0, 'utf8') | ||
| if (beginIndex === -1) { | ||
| return stdout | ||
| } | ||
| const payloadStart = beginIndex + Buffer.byteLength(captured.beginMarker, 'utf8') | ||
| const endIndex = stdout.indexOf(captured.endMarker, payloadStart, 'utf8') | ||
| return endIndex === -1 ? stdout.subarray(payloadStart) : stdout.subarray(payloadStart, endIndex) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Use the final begin marker for raw buffers.
readStdout uses lastIndexOf because shell tracing can echo the fenced command before execution. readCapturedGitBuffer uses the first beginMarker. In that case, binary blob reads can return traced shell text instead of the blob payload.
Proposed fix
- const beginIndex = stdout.indexOf(captured.beginMarker, 0, 'utf8')
+ const beginIndex = stdout.lastIndexOf(captured.beginMarker, stdout.length, 'utf8')Add a raw-buffer regression case with an echoed fence before the real payload.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const beginIndex = stdout.indexOf(captured.beginMarker, 0, 'utf8') | |
| if (beginIndex === -1) { | |
| return stdout | |
| } | |
| const payloadStart = beginIndex + Buffer.byteLength(captured.beginMarker, 'utf8') | |
| const endIndex = stdout.indexOf(captured.endMarker, payloadStart, 'utf8') | |
| return endIndex === -1 ? stdout.subarray(payloadStart) : stdout.subarray(payloadStart, endIndex) | |
| const beginIndex = stdout.lastIndexOf(captured.beginMarker, stdout.length, 'utf8') | |
| if (beginIndex === -1) { | |
| return stdout | |
| } | |
| const payloadStart = beginIndex + Buffer.byteLength(captured.beginMarker, 'utf8') | |
| const endIndex = stdout.indexOf(captured.endMarker, payloadStart, 'utf8') | |
| return endIndex === -1 ? stdout.subarray(payloadStart) : stdout.subarray(payloadStart, endIndex) |
* fix(git): fence buffered WSL login-shell reads Two git paths force the login shell unconditionally and buffer its whole stdout, so the distro's rc banner lands in front of the payload: - gitExecFileAsyncBuffer backs `git show :<path>` blob reads and hands the bytes straight to the diff/blob viewer, so the banner is prepended to displayed file content. - buildNetworkSshPolicyEnv probes `core.sshCommand` and treats any non-empty answer as a user-configured wrapper. A banner reads as configured, so the code skips the `ssh -o BatchMode=yes` fallback and silently disarms the guard that keeps non-interactive SSH from hanging on a prompt. Fencing is opt-in per call site rather than applied to the login-shell branch as a whole: streaming consumers (`git grep`, `ls-files -z`) parse records as they arrive, so an opening marker would be glued onto their first record. Only these two, both buffered by construction, opt in. Blob content can be binary, so the payload is sliced out of the raw bytes; decoding to find the fence would corrupt it. The markers are exposed on the captured command because the shared module is bundled for the renderer and cannot reference Buffer. Note this path is not a rare fallback: `preferWslDirectGit` is only set by gitStatusReadOptionsForWorktree, so every other WSL-routed git call takes the login shell on every invocation. * test(git): use findLast for the ssh-policy call lookup Satisfies the code-quality rule that flags filter-then-index. --------- Co-authored-by: OrcaWin <[email protected]>
* fix(git): fence buffered WSL login-shell reads Two git paths force the login shell unconditionally and buffer its whole stdout, so the distro's rc banner lands in front of the payload: - gitExecFileAsyncBuffer backs `git show :<path>` blob reads and hands the bytes straight to the diff/blob viewer, so the banner is prepended to displayed file content. - buildNetworkSshPolicyEnv probes `core.sshCommand` and treats any non-empty answer as a user-configured wrapper. A banner reads as configured, so the code skips the `ssh -o BatchMode=yes` fallback and silently disarms the guard that keeps non-interactive SSH from hanging on a prompt. Fencing is opt-in per call site rather than applied to the login-shell branch as a whole: streaming consumers (`git grep`, `ls-files -z`) parse records as they arrive, so an opening marker would be glued onto their first record. Only these two, both buffered by construction, opt in. Blob content can be binary, so the payload is sliced out of the raw bytes; decoding to find the fence would corrupt it. The markers are exposed on the captured command because the shared module is bundled for the renderer and cannot reference Buffer. Note this path is not a rare fallback: `preferWslDirectGit` is only set by gitStatusReadOptionsForWorktree, so every other WSL-routed git call takes the login shell on every invocation. * test(git): use findLast for the ssh-policy call lookup Satisfies the code-quality rule that flags filter-then-index. --------- Co-authored-by: OrcaWin <[email protected]>
* fix(git): fence buffered WSL login-shell reads Two git paths force the login shell unconditionally and buffer its whole stdout, so the distro's rc banner lands in front of the payload: - gitExecFileAsyncBuffer backs `git show :<path>` blob reads and hands the bytes straight to the diff/blob viewer, so the banner is prepended to displayed file content. - buildNetworkSshPolicyEnv probes `core.sshCommand` and treats any non-empty answer as a user-configured wrapper. A banner reads as configured, so the code skips the `ssh -o BatchMode=yes` fallback and silently disarms the guard that keeps non-interactive SSH from hanging on a prompt. Fencing is opt-in per call site rather than applied to the login-shell branch as a whole: streaming consumers (`git grep`, `ls-files -z`) parse records as they arrive, so an opening marker would be glued onto their first record. Only these two, both buffered by construction, opt in. Blob content can be binary, so the payload is sliced out of the raw bytes; decoding to find the fence would corrupt it. The markers are exposed on the captured command because the shared module is bundled for the renderer and cannot reference Buffer. Note this path is not a rare fallback: `preferWslDirectGit` is only set by gitStatusReadOptionsForWorktree, so every other WSL-routed git call takes the login shell on every invocation. * test(git): use findLast for the ssh-policy call lookup Satisfies the code-quality rule that flags filter-then-index. --------- Co-authored-by: OrcaWin <[email protected]>
Stack
Merge bottom-up; each PR is based on the one above it.
main#15039#15040#15060ELI5
Same banner problem as #15040, now in git.
When Orca runs git inside WSL, it goes through the login shell, which prints the distro's welcome banner to the same pipe the answer comes back on. Two git paths read that pipe whole and never strip the banner:
Why this wasn't in #15040
I originally left the git login-shell path alone on the belief that its consumers are streaming, where fencing would break them, and that the shell-free "direct git" fast path covered the important cases. Both assumptions were wrong, and checking them is what produced this PR:
preferWslDirectGitis set by exactly one options-builder,gitStatusReadOptionsForWorktree— used only for status-adjacent reads:Every other caller uses
gitOptionsForWorktree, which never sets it. So forgit show, remote/config reads, history, checkout and commit, the login shell isn't a cold fallback — it is the only path, on every call.The two sites fixed here go further and pass
forceLoginShell = true, so they never take the fast path even in principle.Streaming really is a hazard — so fencing is opt-in
The original concern was legitimate, just not universal.
searchWithGitGrepandrunGitLsFilesprocess records as they arrive (andgit grepis killed early oncemaxResultsis hit, so a closing fence may never be written). An opening marker would be glued onto their first record.So the fence is opted into per call site rather than applied to the login-shell branch as a whole. Only the two buffered-by-construction functions opt in. The streaming consumers are untouched — and are incidentally immune anyway, since
ingestGitGrepLinerequires an embedded NUL and discards banner lines outright.Binary safety
Blob content can be binary, so the payload is sliced out of the raw bytes; decoding to a string to find the fence would corrupt a PNG header. The markers are exposed on the captured command because the shared module is bundled for the renderer and so cannot reference
Buffer.Testing
Four tests, all mutation-checked — each fails with the fence disabled, with the real symptom:
expected 'To run a command as administrator…' to be 'line one\nline two\n'Buffer.compare→-1(bytes corrupted)GIT_SSH_COMMANDisundefined— the BatchMode guard is goneBatchMode=yesThe SSH tests drive the real public entry point (
gitExecFileAsyncwithuseConfiguredSshCommandForNetwork) and assert on the env actually handed to git, rather than adding a test-only export.Suite compared against
origin/mainat test-name granularity acrosssrc/main/gitandsrc/shared: zero new failures, and 8 test-names that fail onmainpass here. Typecheck and lint gates clean.