Skip to content

feature_scan: reject output paths that resolve into the corpus - #4579

Open
check3D wants to merge 3 commits into
ItsNotRexed:mainfrom
check3D:fix/feature-scan-output-symlinks
Open

check3D wants to merge 3 commits into
ItsNotRexed:mainfrom
check3D:fix/feature-scan-output-symlinks

Conversation

@check3D

@check3D check3D commented Nov 23, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: New BUILD item

What and why

feature_scan.py --out could overwrite the shader corpus index when the destination reached it through a symlink. The output guard now checks both the path as written and its resolved destination.

Tested

python3 -I tests/test_feature_scan.py passed on Linux. The new CLI regression failed before the fix and now verifies that the command exits with status 2 and leaves the index byte-for-byte intact. CPU-only, synthetic inputs.

AI-assisted (Codex).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A — report output handling only.)

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ran this at affed599 on Windows 11: python -I tests/test_feature_scan.py -> test_feature_scan: OK (0 failed checks, 0 failed tests); git diff --check clean.

The new symlink case itself skipped here (WinError 1314, no symlink privilege), so I checked inside_dir directly with a directory junction (no privilege needed):

inside_dir(alias/index.json where alias -> corpus): True
inside_dir(corpus, corpus):                        True
inside_dir(tmp/other.json, corpus):                False

So the realpath leg resolves an aliased output into the corpus and the guard would exit 2; the abspath leg still covers the non-aliased case. The test's before/after index byte comparison is a good addition. No blocking issue.

@tupacfan04

Copy link
Copy Markdown
Contributor

The fix is correct, but its regression test does not run on Windows CI.

Verified with a junction workaround: --out <junction>\index.json exits 2 with "inside the scanned corpus" and leaves index.json byte-identical, inside_dir returns True on the junction, and the pre-fix abspath-only logic returns False - bug reproduced and fixed. tests/test_feature_scan.py and compileall pass, merge clean.

The gap: tests/test_feature_scan.py:239-242 catches OSError from os.symlink, prints SKIP ... and returns, so the test silently passes. This host skips it (WinError 1314, no SeCreateSymbolicLinkPrivilege), so the new assertion (:249) only ever runs on Linux developer machines. A junction (mklink /J) needs no privilege and would cover the Windows case.

Minor: tools/feature_scan.py:509 now also realpaths non-existent output leaves; harmless, but unasserted.

Approve with the test made portable. AI-assisted review, no game files, no GPU.

@kapitche

Copy link
Copy Markdown
Contributor

Tested affed59 merged with main d0835dd (merge 4dae51e2d, no conflicts) on Linux (WSL2) Python 3.12.16 and native Windows 11 Python 3.13.1: pass.

  • tests/test_feature_scan.py (the file's own runner): OK (0 failed checks, 0 failed tests) on both.
  • Negative control: tools/feature_scan.py from main, same test file: FAILED (0 failed checks, 1 failed test) on Linux and on Windows (the new symlink test; it creates a directory symlink, which worked on this Windows account and is skipped where it cannot be created).
  • Read the diff: inside_dir now checks both the abspath and the realpath spelling of the output and the folder, so an output path under a symlink to the corpus is refused with exit 2 and the corpus index is left byte-identical (the test compares it). The trailing-separator form (os.path.join(root, "")) also avoids the corpus vs corpus-2 prefix mistake.

@DoubleD17 DoubleD17 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.

Reviewed 3d27679a341b700e573db7731dab1458ec795582. A report path outside dxbc can still overwrite dxbc/index.json when the two names are hard links to the same file. In tools/feature_scan.py:531, both the absolute and resolved report paths are outside the corpus. The same_path() check at line 535 only covers the SPIR-V index, so the direct open(..., "w") at line 613 truncates the carved index too.

On Windows 11 with CPython 3.13.3, I created a scratch dxbc/index.json containing [] and an ordinary hard link to it outside dxbc. abspath() and realpath() both keep the report path outside the corpus, while samefile() returns true. The upstream CLI exited 0 and replaced the list with its report object. A second scan of the same scratch directory exited 2 with is not a shader list. The control with a separate report file left the input unchanged. I ran the synthetic case against upstream d0835dd9, using the same feature_scan.py blob, and inspected the PR head statically.

Could you extend the input identity check to the carved index and add a regression that asserts exit 2 and unchanged input bytes for a hard-linked destination?

No game files. AI-assisted.

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.

5 participants