-
Notifications
You must be signed in to change notification settings - Fork 793
fix: use version-aware zip extraction on Windows #563
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
base: dev
Are you sure you want to change the base?
fix: use version-aware zip extraction on Windows #563
Conversation
|
All contributors have signed the CLA. Thank you! ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
Greptile SummaryRefactored Windows zip extraction by creating a shared utility that intelligently selects extraction method based on Windows version and PowerShell availability. This fixes issue #552 where Key Changes
Issues Found
Recommendations
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Downloader as comment-checker/downloader.ts
participant ZipExtractor as shared/zip-extractor.ts
participant OS as OS API
participant Shell as Shell (tar/pwsh/powershell)
Downloader->>ZipExtractor: extractZip(archivePath, destDir)
alt platform === "win32"
ZipExtractor->>OS: release()
OS-->>ZipExtractor: version string (e.g. "10.0.17134")
ZipExtractor->>ZipExtractor: parse build number from version
alt build >= 17134 (Windows 10 1803+)
ZipExtractor->>Shell: spawn tar -xf
Shell-->>ZipExtractor: extraction result
else pwsh exists
ZipExtractor->>OS: existsSync("C:\\Program Files\\PowerShell\\7\\pwsh.exe")
OS-->>ZipExtractor: true
ZipExtractor->>Shell: spawn pwsh Expand-Archive
Shell-->>ZipExtractor: extraction result
else fallback
ZipExtractor->>Shell: spawn powershell Expand-Archive
Shell-->>ZipExtractor: extraction result
end
else Unix/Linux/macOS
ZipExtractor->>Shell: spawn unzip
Shell-->>ZipExtractor: extraction result
end
alt exitCode !== 0
ZipExtractor-->>Downloader: throw Error
else success
ZipExtractor-->>Downloader: void (success)
end
|
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.
Additional Comments (3)
-
src/shared/zip-extractor.ts, line 48 (link)logic: command injection vulnerability:
archivePathanddestDirare directly interpolated into PowerShell command without escaping. If these paths contain single quotes, the command will break or could execute arbitrary code. -
src/shared/zip-extractor.ts, line 55 (link)logic: same command injection vulnerability here for
powershellfallback -
src/shared/zip-extractor.ts, line 27 (link)logic: hardcoded path won't work for custom PowerShell 7 installations or non-standard locations. Use
which pwshor checkPATHenvironment variable insteadWould checking PATH via spawn be acceptable, or should this maintain the file existence check for performance?
5 files reviewed, 3 comments
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.
2 issues found across 5 files
Confidence score: 3/5
- Unescaped single quotes in the PowerShell branch of
src/shared/zip-extractor.tsmean paths containing'will fail to extract, posing a concrete regression for Windows users. - Same path escaping issue as in the prior
pwshlogic remains unresolved, so the zip extraction command is not reliable when filenames include quotes. - Pay close attention to
src/shared/zip-extractor.ts- ensure single quotes are doubled for PowerShell compatibility.
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="src/shared/zip-extractor.ts">
<violation number="1" location="src/shared/zip-extractor.ts:48">
P1: Paths containing single quotes will break the PowerShell command. Escape single quotes by doubling them for PowerShell single-quoted strings.</violation>
<violation number="2" location="src/shared/zip-extractor.ts:55">
P1: Same path escaping issue as the `pwsh` case. Escape single quotes for PowerShell compatibility.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Add shared extractZip utility that selects the best extraction method based on Windows version: - Windows 10 1803+ / Server 2019+: use built-in tar - PowerShell 7+ installed: use pwsh - Fallback: use powershell (Windows PowerShell 5.1) This fixes zip extraction failures when Expand-Archive module cannot be loaded in certain PowerShell environments. Refactor comment-checker, ast-grep, and grep downloaders to use the shared utility. Fixes code-yeongyu#552
- Escape single quotes in paths for PowerShell commands to prevent command injection and handle paths with special characters - Use 'where pwsh' to detect PowerShell 7 instead of hardcoded path, supporting custom installation locations
a4c440f to
8d33e2b
Compare
Add both external-plugin-detector and zip-extractor exports
|
Fixed the issues raised in the review:
Please re-review. Thanks! |
|
@cubic-dev-ai please re-review - the issues have been fixed in commit 8d33e2b |
@popododo0720 I have started the AI code review. It will take a few minutes to complete. |
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.
1 issue found across 5 files
Confidence score: 3/5
- Unconsumed stdout from the
unzip -ochild process insrc/shared/zip-extractor.tscan deadlock extraction when large output is produced, making this a tangible user-impacting regression risk. - Score reflects a medium-severity, reproducible hang scenario that merits a fix before merge to ensure reliable archives handling.
- Pay close attention to
src/shared/zip-extractor.ts– stdout should be ignored or drained to avoid child process deadlocks.
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="src/shared/zip-extractor.ts">
<violation number="1" location="src/shared/zip-extractor.ts:52">
P2: stdout is piped but never consumed, which can cause a deadlock if the extraction process produces significant output (particularly `unzip -o` which lists every file). Since stdout content isn't needed, use `"ignore"` instead of `"pipe"`.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Change stdout from 'pipe' to 'ignore' for all extraction commands. Piped stdout that is never consumed can cause deadlock when the child process produces significant output (e.g., unzip -o lists every extracted file).
|
Fixed the stdout deadlock issue - changed @cubic-dev-ai please re-review |
@popododo0720 I have started the AI code review. It will take a few minutes to complete. |
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.
No issues found across 5 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Summary
Expand-Archivemodule cannot be loadedextractZiputility that selects the best extraction method based on Windows versionChanges
src/shared/zip-extractor.tswith version-aware extraction logic:tarpwshpowershell(Windows PowerShell 5.1)comment-checker/downloader.tsto use shared utilityast-grep/downloader.tsto use shared utilitygrep/downloader.tsto use shared utilityTesting
Both pass successfully.
To verify on Windows:
tarpwshpowershellRelated Issues
Closes #552
Summary by cubic
Fix Windows zip extraction failures with a version-aware strategy selecting tar on Windows 10 1803+/Server 2019+, pwsh if installed, then powershell. Centralizes extraction; updates comment-checker, ast-grep, and ripgrep downloaders; closes #552.
Bug Fixes
Refactors
Written for commit a00bd8e. Summary will update on new commits.