fix(dir): dirtree and getallfiles looped forever symlink cycle #530
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
alerque
treeiterdecides whether to recurse withpath.isdir(lua/pl/dir.lua:480), which stats through symlinks, so a directory symlink gets pushed ontoiterstackand descended into. A link pointing at an ancestor makesdir.dirtreeanddir.getallfilesrun until the process is killed - measured at 17 levels of.../sub/loop/sub/loop/...and still going.dir.walkin the same module already avoids this: #523 made it pickpath.link_attriboverpath.attribwhenfollow_linksis false (dir.lua:292-295). On the same tree,walkfinishes in 2 iterations whiledirtreeruns 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
getallfilestraversing symlinked directories loses that. It is the same trade-off you took forwalkthree commits earlier, but if you would rather have afollow_linksparameter ondirtree/getallfilesmirroringwalk'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), matchingwalkafter #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/loopreported 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 testsexit 0 (Run completed successfully),lua run.lua examplesexit 0. Both existinggetallfilesassertions intests/test-dir.luastill pass.Not run:
bustedandluacheck. 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.dirdirectly, and verified the red-green test myself.