Skip to content

perf(vcs_info): apply the %-quoting patch on first use - #14072

Open
robbyrussell wants to merge 4 commits into
masterfrom
perf/lib-lazy-vcs-info-patch
Open

robbyrussell wants to merge 4 commits into
masterfrom
perf/lib-lazy-vcs-info-patch

Conversation

@robbyrussell

Copy link
Copy Markdown
Member

Standards checklist:

  • The PR title is descriptive.
  • The PR doesn't replicate another PR which is already open.
  • I have read the contribution guide and followed all the instructions.
  • The code follows the code style guide detailed in the wiki.
  • The code is mine or it's from somewhere with an MIT-compatible license.
  • If I used AI tools (ChatGPT, Claude, Gemini, etc.) to assist with this contribution, I've disclosed it below.
  • The code is efficient, to the best of my ability, and does not waste computer resources.
  • The code is stable and I have tested it myself, to the best of my abilities.
  • If the code introduces new aliases, I provide a valid use case for all plugin users down below.

Changes:

  • lib/vcs_info.zsh loaded VCS_INFO_formats and regexp-replace and patched the function body on every startup, although only themes that call vcs_info ever need it.
  • Define a VCS_INFO_formats wrapper that loads and patches the real function the first time it's called, then replaces itself with it. The patch itself is unchanged.
  • autoload doesn't override an existing function, so the wrapper survives a theme's autoload -Uz vcs_info (before or after Oh My Zsh loads) and vcs_info's own autoload -Uz VCS_INFO_*.

Other comments:

Part of a series of small startup-time PRs. Measured on macOS arm64, zsh 5.9: 1.6 ms to 0.1 ms per interactive start.

Since this is the CVE-2021-45444 mitigation, verified through a full Oh My Zsh startup with autoload -Uz vcs_info in the zshrc: the wrapper is in place at startup, the first vcs_info call applies the patch and the wrapper is gone afterwards, a branch named evil%n%m renders literally after prompt expansion (same as with the eager patch), and re-running autoload -Uz vcs_info afterwards keeps the patched function.

🤖 Co-authored with Claude Code

lib/vcs_info.zsh loaded VCS_INFO_formats and regexp-replace and patched
the function body on every startup, although only themes that call
vcs_info ever need it. Define a VCS_INFO_formats wrapper that loads and
patches the real function the first time it's called, then replaces
itself with it. `autoload` doesn't override an existing function, so
the wrapper survives a theme's `autoload -Uz vcs_info` and vcs_info's
own autoload of VCS_INFO_*.

Verified that a branch named `evil%n%m` still renders literally after
prompt expansion, as with the eager patch (CVE-2021-45444 mitigation).
Measured on macOS arm64, zsh 5.9: 1.6 ms -> 0.1 ms per interactive
start.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The wrapper overwrites preloaded or user-defined VCS_INFO_formats implementations.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Defers the vcs_info security patch until first use to reduce shell startup time.

Changes:

  • Adds a lazy VCS_INFO_formats wrapper.
  • Loads, patches, and replaces the function on first invocation.
File summaries
File Description
lib/vcs_info.zsh Implements lazy loading and patching.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/vcs_info.zsh Outdated
# vcs_info. `autoload` doesn't replace an already defined function, so this
# wrapper survives a later `autoload -Uz vcs_info` in a theme or .zshrc, and
# vcs_info's own `autoload -Uz VCS_INFO_formats`.
function VCS_INFO_formats {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 61f12e0. VCS_INFO_formats is now patched in place when already loaded, and the lazy path only installs/uses the wrapper when it is not defined yet.

Copilot AI and others added 3 commits September 6, 2026 15:54
Co-authored-by: robbyrussell <257+robbyrussell@users.noreply.github.com>
Co-authored-by: robbyrussell <257+robbyrussell@users.noreply.github.com>
Co-authored-by: robbyrussell <257+robbyrussell@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The current “already defined” detection doesn’t account for autoload stubs (risking an unpatched real function later) and the already-loaded branch can return a non-zero status when sourcing the file, which may break shells with errexit/ERR_RETURN.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread lib/vcs_info.zsh
# vcs_info. `autoload` doesn't replace an already defined function, so this
# wrapper survives a later `autoload -Uz vcs_info` in a theme or .zshrc, and
# vcs_info's own `autoload -Uz VCS_INFO_formats`.
if (( $+functions[VCS_INFO_formats] )); then
Comment thread lib/vcs_info.zsh
Comment on lines +47 to 49
() {
autoload -Uz +X regexp-replace 2>/dev/null || return 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

4 participants