-
Notifications
You must be signed in to change notification settings - Fork 144
Quote branches argument in zoekt.ts to fix Pipe #506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Adding quotes here fixes zoekt-git-index failing when a pipe is in a branch/tag
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughUpdates the zoekt-git-index invocation to wrap the comma-separated list of revisions passed to -branches in quotes, changing -branches ${revisions.join(',')} to -branches "${revisions.join(',')}". No other logic or flow changes in packages/backend/src/zoekt.ts. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
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 |
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/backend/src/zoekt.ts (1)
1-1
: Replace child_process.exec with spawn/execFile and pass args as an array (prevent RCE in packages/backend/src/zoekt.ts)exec(command) builds a shell string and is vulnerable to command injection via branch/tag names; switch to spawn/execFile with an args array and shell: false.
- import { exec } from "child_process"; + import { spawn } from "child_process"; @@ - const command = [ - 'zoekt-git-index', - '-allow_missing_branches', - `-index ${ctx.indexPath}`, - `-max_trigram_count ${settings.maxTrigramCount}`, - `-file_limit ${settings.maxFileSize}`, - `-branches "${revisions.join(',')}"`, - `-tenant_id ${repo.orgId}`, - `-repo_id ${repo.id}`, - `-shard_prefix ${shardPrefix}`, - repoPath - ].join(' '); - - return new Promise<{ stdout: string, stderr: string }>((resolve, reject) => { - exec(command, (error, stdout, stderr) => { - if (error) { - reject(error); - return; - } - - if (stdout) { - stdout.split('\n').filter(line => line.trim()).forEach(line => { - logger.info(line); - }); - } - if (stderr) { - stderr.split('\n').filter(line => line.trim()).forEach(line => { - // TODO: logging as regular info here and not error because non error logs are being - // streamed in stderr and incorrectly being logged as errors at a high level - logger.info(line); - }); - } - - resolve({ - stdout, - stderr - }); - }) - }); + const args = [ + '-allow_missing_branches', + '-index', ctx.indexPath, + '-max_trigram_count', String(settings.maxTrigramCount), + '-file_limit', String(settings.maxFileSize), + '-branches', revisions.join(','), // zoekt splits this internally + '-tenant_id', String(repo.orgId), + '-repo_id', String(repo.id), + '-shard_prefix', shardPrefix, + repoPath, + ]; + + return new Promise<{ stdout: string; stderr: string }>((resolve, reject) => { + const child = spawn('zoekt-git-index', args, { shell: false }); + let stdoutBuf = ''; + let stderrBuf = ''; + + child.stdout.setEncoding('utf8'); + child.stderr.setEncoding('utf8'); + + child.stdout.on('data', (chunk: string) => { + stdoutBuf += chunk; + chunk.split('\n').filter(l => l.trim()).forEach(l => logger.info(l)); + }); + child.stderr.on('data', (chunk: string) => { + stderrBuf += chunk; + // Non-error logs often come via stderr from zoekt; keep at info + chunk.split('\n').filter(l => l.trim()).forEach(l => logger.info(l)); + }); + child.on('error', reject); + child.on('close', (code) => { + if (code !== 0) { + return reject(new Error(`zoekt-git-index exited with code ${code}`)); + } + resolve({ stdout: stdoutBuf, stderr: stderrBuf }); + }); + });
🧹 Nitpick comments (1)
packages/backend/src/zoekt.ts (1)
50-58
: Guard against commas in ref names (zoekt splits on commas).Git refnames may legally contain commas. Because zoekt parses -branches by strings.Split(value, ","), any comma in a ref mis-splits the list. Consider warning and dropping such refs (or documenting that refs with commas are unsupported). (git-scm.com)
Example insertion before building args:
@@ if (revisions.length > 64) { @@ } + + // Skip refs that contain commas, since zoekt splits -branches on ','. + const invalid = revisions.filter(r => r.includes(',')); + if (invalid.length) { + logger.warn(`Skipping ${invalid.length} revision(s) containing commas: ${invalid.join(' ')}`); + revisions = revisions.filter(r => !r.includes(',')); + }Also applies to: 60-66
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/backend/src/zoekt.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thx for the PR 👍 could you add a changelog entry?
Added a note about fixing zoekt indexing issue with pipe in branch/tag names.
Adding quotes here fixes zoekt-git-index failing when a pipe is in a branch/tag
Fixes #505
Summary by CodeRabbit