← Back to Pull requests

fix(dir): dirtree and getallfiles looped forever symlink cycle #530

Closed
unknown closed this pull request without merging on Oct 28, 2026 08:48 UTC
View on GitHub
unknown unknown commented on Sep 15, 2026 04:23 UTC
Author

treeiter decides whether to recurse with path.isdir (lua/pl/dir.lua:480), which stats through symlinks, so a directory symlink gets pushed onto iterstack and descended into. A link pointing at an ancestor makes dir.dirtree and dir.getallfiles run until the process is killed - measured at 17 levels of .../sub/loop/sub/loop/... and still going.

dir.walk in the same module already avoids this: #523 made it pick path.link_attrib over path.attrib when follow_links is false (dir.lua:292-295). On the same tree, walk finishes in 2 iterations while dirtree runs away. This is the other walker, which that PR did not touch.

This is a behaviour change, not only a bug fix - anyone relying on getallfiles traversing symlinked directories loses that. It is the same trade-off you took for walk three commits earlier, but if you would rather have a follow_links parameter on dirtree/getallfiles mirroring walk's signature, I am happy to do that instead.

Two things I deliberately left alone: the symlink is still reported with mode == true (a directory you do not enter), matching walk after #523; and #494 (permissions in this same function) is untouched to keep the diff to one defect.

<details>
<summary>Verification</summary>

The new test is bounded, so it fails fast rather than hanging CI.

| row | result |
|---|---|
| pristine | test-dir.lua:243: dir.dirtree did not terminate; it followed a directory symlink cycle |
| fix | passes; dirtree = 3 iterations (top.txt, sub, sub/loop reported but not entered), getallfiles = 1 |
| revert the guard | fails at line 243 again |
| also report the symlink as a non-directory | fails at line 248 instead - the symlink leaks into getallfiles |

Repo gates from .github/workflows/unix_build.yml, run on Lua 5.4.7 with LuaFileSystem 1.9.0: lua run.lua tests exit 0 (Run completed successfully), lua run.lua examples exit 0. Both existing getallfiles assertions in tests/test-dir.lua still pass.

Not run: busted and luacheck. There is no luarocks on the machine I used and I could not install one, so I have left those unticked rather than claim them. grep -rn "dirtree\|getallfiles" spec/ returns nothing, so no busted spec reaches the changed function.

Note for anyone searching: closed issue #265 is a different cause (ngx_lua coroutine substitution), not this.

</details>

Disclosure: this fix was prepared with AI assistance (Claude). I reviewed it, reproduced the runaway and the fix against pl.dir directly, and verified the red-green test myself.

Diff: 322 lines (+241 / -81) across 4 files Reviewer: alerque Review duration: 62184m
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.42) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 322 lines diff across 4 files
0.42
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.346
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #530"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 41.9% (MEDIUM) · Higher = larger blast radius
41.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 18.1% · Safe to merge
18.1%