Skip to content

fix(opencode): handle literal Windows archive paths - #43038

Closed
ddism wants to merge 2 commits into
anomalyco:devfrom
ddism:windows-archive-paths
Closed

ddism wants to merge 2 commits into
anomalyco:devfrom
ddism:windows-archive-paths

Conversation

@ddism

@ddism ddism commented Aug 17, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #43036

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Pass Windows archive and destination paths through child-process environment variables instead of interpolating them into a PowerShell command.

It also switches Expand-Archive from -Path to -LiteralPath. This preserves apostrophes in valid paths and prevents characters such as [ and ] from being interpreted as wildcards.

A Windows regression test covers archive and destination paths containing both kinds of characters.

How did you verify your code works?

  • Ran bun test test/util
  • 120 tests passed with 0 failures
  • Verified extraction using paths such as archive's [copy].zip and destination's [copy]
  • Ran Prettier checks on the changed files

Screenshots / recordings

N/A — this is a non-UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

  1. packages/opencode/src/util/archive.ts:6 — solid fix: routing the paths through $env: removes both the single-quote injection hole (a path like x'; Remove-Item ...) and the wildcard/globbing misparse that motivated this ([copy] under non-literal -Path). Consider also asserting in Process.run's contract (or a comment here) that env merges with process.env — if it ever switches to replace-semantics, PowerShell on Windows can fail to start without SystemRoot, and this call site would be the reason.

  2. packages/opencode/src/util/archive.ts:9 — with paths no longer embedded in the command string, failures now log a command that contains only $env:... placeholders, so a broken extract shows "Expand-Archive failed" with no clue which file was involved — make sure the thrown error from Process.run still carries stderr (and ideally the resolved OPENCODE_ARCHIVE_PATH value) for debuggability.

  3. packages/opencode/test/util/archive.test.ts:7 — the guard if (process.platform !== "win32") return makes the test silently pass on Linux/macOS CI; prefer test.skipIf(process.platform !== "win32") so the skip is visible in reports and someone notices when zero Windows runs happened in a PR touching Windows-only behavior.

  4. Nit — coverage gap worth closing while here: the same literal-path hazard usually applies to the non-Windows branch (tar/unzip with odd filenames) and to any sibling helpers in this module interpolating paths into shell strings — a quick audit comment or follow-up ticket reference would lock the scope of the fix.

Overall: correct, minimal security/robustness fix with a test that exercises exactly the reported pathology (apostrophes + brackets in archive and destination names) end-to-end via real PowerShell. Nice. Thanks!

@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

  • packages/opencode/src/util/archive.ts:9 — strong fix: moving paths out of the interpolated command string into env vars eliminates both the literal-path breakage (', [, ] in names) and a PowerShell injection vector the old quoting had. -LiteralPath is the right parameter.
  • packages/opencode/test/util/archive.test.ts:7 — good regression case with apostrophes and brackets in both source and destination names. Since the body early-returns off-Windows, confirm Windows CI actually runs this suite, otherwise it's dead coverage locally.
  • Nit: consider asserting that a malicious-looking name like foo'; Remove-Item -Recurse ~; 'bar.zip also extracts safely — that's the property this fix really guarantees.
  • No blocking issues found.

@ddism ddism closed this Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows archive extraction fails for paths containing apostrophes or wildcard characters

2 participants