Skip to content

perf(supply-chain): O(n^2) hot paths in claimed-span dedup and dedup_installs #149

Closed

Description

@thehoff

Surfaced by Codex peer review of PR #148 (WARN, not BLOCKER).

Two hot paths in src/hooks/supply_chain_gate.rs are O(n^2) in the number of detected install spans inside a single command string:

  • claimed.iter().any(...) - linear scan per match in detect_installs_into
  • dedup_installs() - pairwise compare in installs_equivalent

Recursion depth is capped but the per-command width is not. A crafted command containing many repeated install-shaped segments can force superlinear work.

Severity: WARN. Not a bypass. Realistic ceiling for normal commands is single digits. Pathological adversarial input is the concern.

Proposed fix: switch claimed to an interval tree (or sorted Vec with binary search); switch dedup_installs to a HashSet keyed on a stable hash of the install signature. Both are mechanical refactors with no behaviour change.

Acceptance: a stress test fixture with 1000+ install-shaped spans completes in sub-millisecond. Existing 2,600+ tests still pass.

Discovered: 2026-05-23 during Codex review of #148.

Generated with Claude Code (https://claude.com/claude-code)

Activity

  1. thehoff commented on May 26, 2026

    @thehoff
    OwnerAuthor

    Fixed in v0.1.11 via #184.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions