Skip to content

fix(extractors/bash): resolve dirname cmdsubst and dotdot suffix in source paths (#2596) - #2690

Closed
hudsonwa wants to merge 1 commit into
Graphify-Labs:v8from
hudsonwa:fix/obsidian-case-collision
Closed

hudsonwa wants to merge 1 commit into
Graphify-Labs:v8from
hudsonwa:fix/obsidian-case-collision

Conversation

@hudsonwa

Copy link
Copy Markdown
Contributor

Summary

Fixes two of the four broken source path forms reported in #2596:

  • Form 3 (highest-impact — 22 of 36 dropped statements in the reporter's repo): source "$(dirname "$VAR")/lib/x.sh" — command substitution in the source argument. The new _BASH_SOURCE_DIRNAME regex recognises the $(dirname "$VAR") idiom on the source line, the same way _BASH_DIRNAME_IDIOM already recognises it on assignment lines. It resolves to var_bases[VAR].parent (falling back to script_dir.parent when VAR is untracked), then resolves the literal suffix against it.

  • Form 4: source "$VAR/../lib/y.sh" — .. in the literal suffix. When the base comes from a tracked var_bases entry (a known directory), .. is safe and is resolved via os.path.normpath. The .. rejection is kept on the script-dir-guess path where the base is uncertain.

Forms 1 (second-level variable assignment) and 2 (assignment inside if blocks) are left for a follow-up — they require deeper changes to var_bases construction and are lower frequency.

How to Test

  1. uv run --frozen pytest tests/test_extract.py -k "dirname_cmdsubst or dotdot_suffix" -q --tb=short — 4 new tests, all pass
  2. uv run --frozen pytest tests/test_extract.py -k "bash" -q --tb=short — all 46 bash tests pass (no regressions)
  3. Full suite: uv run --frozen pytest tests/ -q --tb=short — 4323 passed (12 pre-existing skillgen/labeling failures on clean v8, unrelated to this change)

RED→GREEN proof: with the fix reverted (clean v8), the 3 new resolution tests fail (0 edges produced). With the fix applied, all 4 pass (2 import edges produced + guard test verifying .. is still rejected for untracked vars).

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Fixes #2596

…ource paths (Graphify-Labs#2596)

Form 3: Recognise $(dirname "$VAR") in source arguments — the dominant
broken form (22 of 36 dropped statements in the reporter's repo).  Treat
$(dirname "$VAR") as var_bases[VAR].parent (or script_dir.parent when
untracked), then resolve the literal suffix against it.  Mirrors the
existing _BASH_DIRNAME_IDIOM handler on assignment lines.

Form 4: Allow .. in the literal suffix when the base comes from a tracked
var_bases entry (a known directory).  Keep the .. rejection on the
script-dir-guess path where the base is uncertain.

Adds 4 regression tests: dirname with tracked var, dirname with untracked
var, dotdot suffix with tracked var, and dotdot suffix still rejected on
the script-dir-guess path.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. 1 change(s) tested, no difference found (not proven).


Graphify review — findings

This PR modifies the Bash extractor's source statement resolution to handle two additional forms of variable-built source arguments. It adds support for the $(dirname "$VAR") command-substitution idiom appearing directly in a source argument (resolving it via tracked variable bases or a script-dir fallback), and threads an allow_dotdot parameter through _bash_source_suffix so .. traversal segments are permitted only when the base comes from a known tracked variable. The change also adds several new test cases in tests/test_extract.py covering these dirname/command-substitution and ..-suffix scenarios (tracked and untracked variable cases). The large number of listed changed test symbols suggests line-shift or renumbering effects across the test file's rationale entries.

No blocking issues surfaced. 6 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 328 functions depend on the 328 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract_bash() — 38 callers, 10 callees
  • worse: walk() — 1 callers, 9 callees

Verification — 328 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 328 function(s) in the blast radius were not formally verified this run

Formal verification

No difference found (not proven): No behavior difference found in \_bash\_source\_suffix (not a proof).

The verifier ran both versions of \_bash\_source\_suffix on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify extract\_bash.

The verifier did not have enough to check extract\_bash, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

· 2 more finding(s) on lines outside this diff (see the check run).

safishamsi added a commit that referenced this pull request Aug 14, 2026
The #2690 form-3 (`$(dirname …)`) branch had no `..` guard and the tracked
form-4 branch let `..` walk past the base to an arbitrary host path, so a
hostile corpus could make the extractor stat and record an out-of-tree file
(source "$(dirname "$VAR")/../../../../etc/passwd") — a corpus-side info leak,
since resolve_bash_source_edges only filters *resolved* cross-file edges, not
the extractor's own edge/probe. Adds a lexical _within_tree gate: form 3
rejects `..` outright (its base is a guess), and a tracked form-4 base may
reach a sibling via $VAR/../lib but cannot escape past base.parent. Adds two
traversal-rejection tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@hudsonwa

Copy link
Copy Markdown
Contributor Author

Closing — the fix was merged upstream in b345dc4 (fix(extractors/bash): resolve dirname cmdsubst and dotdot suffix in source paths #2596). Thanks for the merge!

@hudsonwa hudsonwa closed this Aug 15, 2026
@safishamsi

Copy link
Copy Markdown
Member

For the record: this shipped in v0.9.44 (on PyPI), cherry-picked onto v8 with your authorship preserved. I added a corpus-root containment gate on top so a .. source path can't resolve outside the tree. Thanks @hudsonwa.

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.

bash extractor: source paths built from a second-level variable or from $(dirname "$VAR") are silently dropped

2 participants