shader: harden directory, symlink, and output path guards in probe_root_devices with CLI suite #2889
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2889
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2889"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Ammmae0x on GitHub · 2026-11-26 16:37 UTC · original
Ammmae0x:shader/probe-root-devices-cli→main· +601 −3 · 3 files · 2 commits · merged 2026-11-28 09:11 UTCChange
Harden upfront directory, file, and output-path guards in
tools/probe_root_devices.py, and add a standalone CLI, path-guard, atomic-replace, and temp-copy mutation suite (tests/probe_root_devices_cli_check.py, registered viatests/cmake/shader_probe_root_devices_cli.cmake).main(argv=None): rejects non-directory--bin, missing/non-file control.csoshaders, non-directorybuildpath, filedest.parent, directorydest, missing/non-filesix-apis.jsoninventory, and missing/non-file PE images with a clear one-line message and clean exit1.mainis clearer error messages and, for a directory atdestor a file atdest.parent, failing before the probe runs instead of after it.mainalready exits1with a one-lineprobe_root_devices: …message and no traceback on the missing--bin, control.cso, inventory and imageOSErrorpaths.destmay be a symlink or hardlink tosix-apis.json, anddest.parentmay be a directory symlink.temporary.replace(dest)renames over the directory entry, so it never writes through a link and the inventory is untouched; the suite now has positive controls proving all three restored layouts.dest.resolve().is_relative_to(args.build.resolve())(parser.error, exit2) ahead ofargs.build.is_dir()and atomicNamedTemporaryFile+replacewith temp unlink cleanup on failure.Verification
Commit:
583c8976(Linux,python3 -Bwith a local venv providingpefile;sys.getwindowsversionshimmed, as in the reviewers' Linux runs):python3 -B tests/probe_root_devices_cli_check.py -v-> 8/8 tests OK (atomic JSON write & 0 leftover temps, upfront--bin/control.cso/build/inventory/image guards + real missingroot_device_probe.execlean exit1,destdir/file-parent/inside-build guards, restored symlink/hardlinkdestand symlinkeddest.parentlayouts, guards failing before the guarded read/measure,os.replacefailure preserving prior bytes & 0 temps, Py3.14-safe argparse, and 5 temp-copy mutations).python3 -B tests/probe_root_devices_check.py-> 11/11 tests OK (untouched).python3 -B tests/form_coverage_check.py-> passed (exit 0).python3 -B tests/docs_links_check.py-> passed (29 Markdown files, 545 links, exit 0).python3 -B tests/bidi_controls_check.py-> passed (2048 files, exit 0).args.build.is_dir(),dest.parent.is_file(), inventoryis_file(), and imageis_file()one by one each causedtests/probe_root_devices_cli_check.pyto fail (exit 1); re-adding thedest.is_symlink()guard also failed the suite. All 5 killed; source restored cleanly (git statusshows only the two intended files).Build and test on Windowswas not run here (Linux host, no Windows toolchain); it still needs a Windows run.Evidence and follow-up
All fixtures are synthetic in-memory PE32+ / DXBC /
RTS0blobs and mockedsubprocess.runprobe outputs insideTemporaryDirectory; zero external or game files are used.Checklist
AI-assisted.
@pigalot on GitHub · 2026-11-27 19:56 UTC · original · requested changes
I reviewed
31df1f3cmerged intomain454fc0ed(treef086be93, clean merge).What I ran.
out\pe-env\Scripts\python.exe -B tests\probe_root_devices_cli_check.py: 6/6 OK.tests\probe_root_devices_check.py: OK.git diff --checkis clean.What the guards change compared with
main. I ran the new suite againstmain'stools/probe_root_devices.py. All 6 tests fail, but only on message text and on the mutation lines being absent.mainalready exits 1 with a one-lineprobe_root_devices: …message and no traceback in each of these cases:--bin;.csoor inventory;Each of these already raises an
OSErrorthat the existingexceptcatches. So for those cases the gain is clearer wording. For a directory atdestor a file atdest.parent, the gain is also failing before the probe runs instead of after it. Both are fine.Three of the guards refuse cases that work correctly on
main. I used the suite's own_create_fixtureand_run_mainand ran each case on both versions:maindesthardlinked tosix-apis.jsonOutput path must not alias inventorydesta symlink tosix-apis.jsonOutput path must not be a symlinkout/callsa directory symlink to another folderOutput directory must not be a symlinktemporary.replace(dest)renames over the directory entry; it doesn't write through it. So a link atdestcan't clobber the inventory, and the hardlink test's "without overwriting inventory" holds onmaintoo. The parent-symlink refusal is a real regression: anout/orout/callslinked to another drive stops working.Requested change. Drop the
dest.is_symlink(), alias (resolve/samefile) anddest.parent.is_symlink()refusals, together with their tests and mutations. Alternatively, explain what failure they prevent that the atomic replace doesn't already. Please also reword the body: these cases already exit 1 without a traceback onmain.Comparison script (scratch, uses the PR's test helpers)
The
out/callscase movescallsto a sibling folder and links it back withsymlink_to(..., target_is_directory=True)before the same call.Verdict: request changes on
31df1f3c.Environment: Windows 11 25H2 build 26200.9974; Python 3.12.10 (
out\pe-env); symlinks created with Developer Mode on.CI: all required checks pass on
31df1f3c. There are no reviews or threads.This reply was AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-28 07:32 UTC · original
Thanks for the guard work and the CLI suite. I rechecked head
31df1f3cmerged into currentmain(clean merge; Linux, Python 3.13,sys.getwindowsversionshimmed). The change request on this same commit is still open, so here is what's left to fix.Must fix
main. I ran the earlier review's comparison script (it uses the suite's own_create_fixture/_run_main) against both copies oftools/probe_root_devices.py:desthardlinked tosix-apis.json:mainexit 0, report written, inventory unchanged. PR exit 1,Output path must not alias inventory.desta symlink tosix-apis.json:mainexit 0, the link is replaced by the report. PR exit 1,Output path must not be a symlink.out/callsa directory symlink:mainexit 0, report written. PR exit 1,Output directory must not be a symlink.temporary.replace(dest)renames over the directory entry, somainnever writes through a link. Please drop thedest.is_symlink(), alias (resolve/samefile) anddest.parent.is_symlink()checks along with their tests and mutations, or show a failure that the atomic replace doesn't already prevent.Should fix
2. If the parent check stays, it's inconsistent. With
outitself a directory symlink, the PR exits 0 and writes the report, butout/callsis refused.is_symlink()only looks at the last path component.3. Of the six new guards the suite doesn't mutate, four are pinned only by their message text. Deleting the
args.build.is_dir(),dest.parent.is_file(), inventoryis_file()or imageis_file()check one at a time and runningpython -B tests/probe_root_devices_cli_check.pystill gives exit 1. The test goes red only on wording, e.g.'Build directory is not a directory' not found in 'probe_root_devices: Build image is missing or not a file: ...'.4. The body says these cases now exit 1 "(zero tracebacks)", but
mainalready does that. With a directory atdest, and withcompute_tables.csomissing,mainexits 1 with a one-line message and no traceback. Please describe the gain as clearer messages and, for a directory atdestor a file atdest.parent, failing before the probes.This comment was AI-assisted.
@Ammmae0x on GitHub · 2026-11-28 08:07 UTC · original
Addressed in
583c8976(pigalot / JohnConnorNPC, current head):dest.is_symlink(),dest.parent.is_symlink(), and the hardlink/alias (resolve/samefile) refusal. Added positive controls proving the restoredmainbehaviour: hardlinkeddest, symlinkeddest, and symlinkeddest.parentall exit 0 with the report written and the inventory unchanged, via the atomictemporary.replace(dest).test_guards_fail_before_reading_or_measuringasserts each guard fails before the guarded read/measure is attempted (build guard also wins over a missing inventory by ordering). The message assertions remain as the CLI contract.dest/file-parent cases;mainalready exited 1 with a one-line message and no traceback on thoseOSErrorpaths.Verification (Linux,
python3 -Bwith a venv providingpefile,sys.getwindowsversionshimmed):tests/probe_root_devices_cli_check.py -v8/8 OK;tests/probe_root_devices_check.py11/11 OK;form_coverage_check.py,docs_links_check.pyandbidi_controls_check.pyall exit 0. Spot-mutation audit: disablingargs.build.is_dir(),dest.parent.is_file(), inventoryis_file(), and imageis_file()one by one each failed the suite (exit 1), and re-adding thedest.is_symlink()guard also failed it — all 5 killed, source restored cleanly. Windows CTest was not run here (Linux host); it still needs a Windows run.AI-assisted.
@pigalot on GitHub · 2026-11-28 09:11 UTC · original · approved these changes
Retested
583c8976integrated overmain3f780716(treef75aa158). The merge is clean andgit diff --checkis clean.My earlier findings on
31df1f3c. All three are addressed.583c8976removes thedest.is_symlink(),dest.parent.is_symlink()and inventory-alias (resolve/samefile) refusals. The remaining guards are the ones I didn't object to:--bin/build directory, control.cso, inventory and image files, a directory atdest, and a file atdest.parent.test_atomic_replace_allows_symlink_and_hardlink_destcovers the three layouts from my table: a hardlinkeddest, a symlinkeddest, and a symlinkedout/calls. Each exits 0, writes the report and leavessix-apis.jsonbyte-identical. This ran for real on Windows here, and symlink creation worked, so nothing was skipped.What I ran. I ran
ctest --test-dir out/build/<preset> --no-tests=error -R 'probe_root_devices'indevandrelease.shader_probe_root_devices_cli_check(8 tests) andprobe_root_devices_check(11 tests) pass in both.Control and mutants. Each changes
tools/probe_root_devices.py, then runstests/probe_root_devices_cli_check.py:main(control)dest_dir_file_parent…,fast_temp_copy_mutationsand othersdest.is_symlink()refusalatomic_replace_allows_symlink_and_hardlink_destdest.is_dir()guarddest.parent.is_file()guard--binis_dir()guard.csois_file()guardis_file()guardis_dir()guardis_file()guardRestored afterwards; the worktree matches the trial merge.
Non-blocking. The comment at the top of
tests/cmake/shader_probe_root_devices_cli.cmakestill says "upfront path/symlink/hardlink guard". The suite now checks that symlinks and hardlinks are allowed.Verdict: approve on
583c8976. This supersedes my changes-requested review on31df1f3c.Environment: Windows 11 25H2 build 26200.9974;
out/pe-envPython 3.12.10.CI:
Build and test on Windowspasses on583c8976.This reply was AI-assisted.