ffx: add upfront path guards and atomic writes to ffx_working_set_delta with CLI suite #2608

Merged
Ammmae0x merged 1 commit from upstream-pr/2616 into main 2026-11-25 23:35:10 +00:00
Ammmae0x commented 2026-11-25 23:26:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T23:26:09Z.


Change

Harden upfront path validation and atomic output writes in tools/ffx_working_set_delta.py and add a pure-Python CLI/error test suite in tests/ffx_working_set_delta_cli_check.py (registered as ffx_working_set_delta_cli_check in CMakeLists.txt with TIMEOUT 60):

  • Validate args.image upfront (reject directories and missing/non-regular files) before calling generate().
  • Validate args.output upfront (require .cpp suffix, reject symlinks, existing directories, non-directory parent/ancestors, and same-path / hardlink-samefile collisions with args.image).
  • Replace direct args.output.write_text(...) with sibling-temp _write_atomic(...) creating missing parent directories and unlinking the temporary file on any failure (0 leftover .tmp files), catching (OSError, ValueError, struct.error, pefile.PEFormatError) cleanly on stderr with no tracebacks and preserving existing tests and exit codes.

AI-assisted.

Verification

Tested on commit 986d7546 (rebased on upstream/main) with out\pe-env\Scripts\python.exe -B:

  • out\pe-env\Scripts\python.exe -B tests\ffx_working_set_delta_check.py -v: 7 tests OK (exit 0).
  • out\pe-env\Scripts\python.exe -B tests\ffx_working_set_delta_cli_check.py -v: 7 tests OK (exit 0), covering nested-dir atomic .cpp creation and overwrite with 0 .tmp files, --package forwarding, sys.argv / __main__ entrypoint, missing/directory image rejection, invalid PE bytes, non-.cpp/directory/symlink/file-parent/samefile output guards, atomic replace failure cleanup, and Python 3.14-safe argparse errors.
  • Spot-mutation negative control: temporarily disabled 4 guards one by one (image.is_dir(), output.is_symlink(), output.is_dir(), and tmp_path.unlink cleanup); 4/4 mutations killed by tests\ffx_working_set_delta_cli_check.py and restored cleanly.
  • out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py: passed (exit 0).
  • out\pe-env\Scripts\python.exe -B tests\docs_links_check.py: passed (exit 0).
  • out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py: passed (exit 0).

Evidence and follow-up

All fixtures in tests/ffx_working_set_delta_cli_check.py are pure-Python synthetic placeholders and invalid-PE byte controls (MIT License). No existing CLI flags, exit codes, or build prerequisites changed.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6615862587 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2616). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T23:26:09Z. --- ## Change Harden upfront path validation and atomic output writes in `tools/ffx_working_set_delta.py` and add a pure-Python CLI/error test suite in `tests/ffx_working_set_delta_cli_check.py` (registered as `ffx_working_set_delta_cli_check` in `CMakeLists.txt` with `TIMEOUT 60`): - Validate `args.image` upfront (reject directories and missing/non-regular files) before calling `generate()`. - Validate `args.output` upfront (require `.cpp` suffix, reject symlinks, existing directories, non-directory parent/ancestors, and same-path / hardlink-`samefile` collisions with `args.image`). - Replace direct `args.output.write_text(...)` with sibling-temp `_write_atomic(...)` creating missing parent directories and unlinking the temporary file on any failure (0 leftover `.tmp` files), catching `(OSError, ValueError, struct.error, pefile.PEFormatError)` cleanly on stderr with no tracebacks and preserving existing tests and exit codes. AI-assisted. ## Verification Tested on commit `986d7546` (rebased on `upstream/main`) with `out\pe-env\Scripts\python.exe -B`: - `out\pe-env\Scripts\python.exe -B tests\ffx_working_set_delta_check.py -v`: 7 tests OK (exit 0). - `out\pe-env\Scripts\python.exe -B tests\ffx_working_set_delta_cli_check.py -v`: 7 tests OK (exit 0), covering nested-dir atomic `.cpp` creation and overwrite with 0 `.tmp` files, `--package` forwarding, `sys.argv` / `__main__` entrypoint, missing/directory image rejection, invalid PE bytes, non-`.cpp`/directory/symlink/file-parent/samefile output guards, atomic replace failure cleanup, and Python 3.14-safe `argparse` errors. - Spot-mutation negative control: temporarily disabled 4 guards one by one (`image.is_dir()`, `output.is_symlink()`, `output.is_dir()`, and `tmp_path.unlink` cleanup); 4/4 mutations killed by `tests\ffx_working_set_delta_cli_check.py` and restored cleanly. - `out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py`: passed (exit 0). - `out\pe-env\Scripts\python.exe -B tests\docs_links_check.py`: passed (exit 0). - `out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py`: passed (exit 0). ## Evidence and follow-up All fixtures in `tests/ffx_working_set_delta_cli_check.py` are pure-Python synthetic placeholders and invalid-PE byte controls (MIT License). No existing CLI flags, exit codes, or build prerequisites changed. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-26 00:00:59 +00:00
tedin7 commented 2026-11-26 00:01:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:33:59Z.

Review: COMMENTED


Review of head 986d7546 (comment only).

Checked:

  • tools/ffx_working_set_delta.py: the upfront path guards (image dir/missing, .cpp suffix, symlink, directory, non-directory ancestors, same-path/samefile) and _write_atomic (sibling temp file, replace, temp unlinked on any failure). Exit codes and stderr handling are unchanged for existing callers; struct.error is now caught cleanly.
  • Sibling slice: #1948 (already merged) hardened validation of the same tool; this PR builds on it and no other open PR touches it.
  • Test tests/ffx_working_set_delta_cli_check.py is registered in CMakeLists.txt and guards the new behavior through the CLI.

Commands run (Linux, venv with pefile):

  • python3 -B tests/ffx_working_set_delta_cli_check.py: 7 tests OK
  • python3 -B tests/ffx_working_set_delta_check.py: 7 tests OK
  • python3 tests/docs_links_check.py: ok
  • python3 tests/bidi_controls_check.py: ok
  • git diff --check origin/main...HEAD: clean
  • Mutation 1: symlink guard disabled -> the new suite fails (2 failures).
  • Mutation 2: temp-file cleanup disabled -> the new suite fails (1 failure).
    Both mutations were reverted.

No concerns found.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6066468610 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2616#pullrequestreview-6066468610). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T23:33:59Z. **Review:** COMMENTED --- Review of head 986d7546 (comment only). Checked: - `tools/ffx_working_set_delta.py`: the upfront path guards (image dir/missing, `.cpp` suffix, symlink, directory, non-directory ancestors, same-path/samefile) and `_write_atomic` (sibling temp file, `replace`, temp unlinked on any failure). Exit codes and stderr handling are unchanged for existing callers; `struct.error` is now caught cleanly. - Sibling slice: #1948 (already merged) hardened validation of the same tool; this PR builds on it and no other open PR touches it. - Test `tests/ffx_working_set_delta_cli_check.py` is registered in `CMakeLists.txt` and guards the new behavior through the CLI. Commands run (Linux, venv with pefile): - `python3 -B tests/ffx_working_set_delta_cli_check.py`: 7 tests OK - `python3 -B tests/ffx_working_set_delta_check.py`: 7 tests OK - `python3 tests/docs_links_check.py`: ok - `python3 tests/bidi_controls_check.py`: ok - `git diff --check origin/main...HEAD`: clean - Mutation 1: symlink guard disabled -> the new suite fails (2 failures). - Mutation 2: temp-file cleanup disabled -> the new suite fails (1 failure). Both mutations were reverted. No concerns found. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 00:01:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:34:44Z.


Win2025 WARP receipt for head 986d7546.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 986d75468a6fb7211ff0105c93ccedc2e4f9f229:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target cpu_working_set_delta_lifted -- -j 2): 1.01s (configure 3.31s)
    • Test (ctest --preset dev -R 'ffx_working_set_delta' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (7.33s: ffx_working_set_delta_check 2.66s, ffx_working_set_delta_cli_check 7.12s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target cpu_working_set_delta_lifted -- -j 2): 7.34s (configure 3.41s)
    • Test (ctest --preset release -R 'ffx_working_set_delta' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (4.47s: ffx_working_set_delta_check 1.71s, ffx_working_set_delta_cli_check 4.31s)
  • sccache: 2/15 hits; wall 26.3s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7177757761 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2616#issuecomment-7177757761). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T23:34:44Z. --- Win2025 WARP receipt for head 986d7546. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `986d75468a6fb7211ff0105c93ccedc2e4f9f229`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target cpu_working_set_delta_lifted -- -j 2`): `1.01s` (configure `3.31s`) - Test (`ctest --preset dev -R 'ffx_working_set_delta' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`7.33s`: `ffx_working_set_delta_check` `2.66s`, `ffx_working_set_delta_cli_check` `7.12s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target cpu_working_set_delta_lifted -- -j 2`): `7.34s` (configure `3.41s`) - Test (`ctest --preset release -R 'ffx_working_set_delta' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`4.47s`: `ffx_working_set_delta_check` `1.71s`, `ffx_working_set_delta_cli_check` `4.31s`) - `sccache`: 2/15 hits; wall `26.3s` AI-assisted; commands listed were executed locally.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2608
No description provided.