runtime: add upfront CLI guards and atomic writes to bink_heap_aot with CLI suite #2619

Merged
Ammmae0x merged 1 commit from upstream-pr/2627 into main 2026-11-25 23:38:18 +00:00
Ammmae0x commented 2026-11-25 23:33:44 +00:00 (Migrated from github.com)

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


Change

Add upfront CLI validation and atomic sibling-temp writes in tools/bink_heap_aot.py and add a pure-Python CLI/error test suite in tests/bink_heap_aot_cli_check.py (registered as runtime_bink_heap_aot_cli_check in CMakeLists.txt with TIMEOUT 60):

  • Make main(argv=None) -> int return 0 and propagate via raise SystemExit(main()) under __main__.
  • Validate args.image upfront (reject directories and missing/non-regular files), reject negative --entries RVAs and blank --group-entry strings, and validate args.output (require .cpp suffix, reject symlinks, directories, non-directory parent/ancestors, and same-path / hardlink-samefile collisions with args.image) before calling generate().
  • 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 (ValueError, OSError, struct.error, pefile.PEFormatError) cleanly on stderr with no tracebacks and preserving tests/bink_heap_aot_check.py.

AI-assisted.

Verification

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

  • out\pe-env\Scripts\python.exe -B tests\bink_heap_aot_check.py -v: 12 tests OK (exit 0).
  • out\pe-env\Scripts\python.exe -B tests\bink_heap_aot_cli_check.py -v: 8 tests OK (exit 0), covering nested-dir atomic .cpp creation and overwrite with 0 .tmp files, --entries / --group-entry forwarding, sys.argv / __main__ entrypoint, dir/missing image, invalid PE bytes, negative --entries, empty/blank --group-entry, non-.cpp/dir/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 (negative --entries, blank --group-entry, output.is_symlink(), and tmp_path.unlink cleanup); 4/4 mutations killed by tests\bink_heap_aot_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/bink_heap_aot_cli_check.py are pure-Python synthetic placeholders and invalid-PE 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:6615963115 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2627). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T23:33:44Z. --- ## Change Add upfront CLI validation and atomic sibling-temp writes in `tools/bink_heap_aot.py` and add a pure-Python CLI/error test suite in `tests/bink_heap_aot_cli_check.py` (registered as `runtime_bink_heap_aot_cli_check` in `CMakeLists.txt` with `TIMEOUT 60`): - Make `main(argv=None) -> int` return `0` and propagate via `raise SystemExit(main())` under `__main__`. - Validate `args.image` upfront (reject directories and missing/non-regular files), reject negative `--entries` RVAs and blank `--group-entry` strings, and validate `args.output` (require `.cpp` suffix, reject symlinks, directories, non-directory parent/ancestors, and same-path / hardlink-`samefile` collisions with `args.image`) before calling `generate()`. - 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 `(ValueError, OSError, struct.error, pefile.PEFormatError)` cleanly on stderr with no tracebacks and preserving `tests/bink_heap_aot_check.py`. AI-assisted. ## Verification Tested on commit `e766269c` (rebased on `upstream/main`) with `out\pe-env\Scripts\python.exe -B`: - `out\pe-env\Scripts\python.exe -B tests\bink_heap_aot_check.py -v`: 12 tests OK (exit 0). - `out\pe-env\Scripts\python.exe -B tests\bink_heap_aot_cli_check.py -v`: 8 tests OK (exit 0), covering nested-dir atomic `.cpp` creation and overwrite with 0 `.tmp` files, `--entries` / `--group-entry` forwarding, `sys.argv` / `__main__` entrypoint, dir/missing image, invalid PE bytes, negative `--entries`, empty/blank `--group-entry`, non-`.cpp`/dir/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 (negative `--entries`, blank `--group-entry`, `output.is_symlink()`, and `tmp_path.unlink` cleanup); 4/4 mutations killed by `tests\bink_heap_aot_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/bink_heap_aot_cli_check.py` are pure-Python synthetic placeholders and invalid-PE 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:01:04 +00:00
tedin7 commented 2026-11-26 00:01:04 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head e766269c (comment only).

Result: sound, no blocking findings.

What I checked

  • tools/bink_heap_aot.py: _validate_args runs before generate(); _write_atomic writes a sibling temp file and replaces it, and removes the temp file on any failure. main() now returns 0 and exits via SystemExit(main()). The old suffix/same-path check is kept, now with a hardlink samefile check too.
  • tests/bink_heap_aot_cli_check.py is registered in CMakeLists.txt next to bink_heap_aot_check, with a 60 s timeout. The existing suite is untouched.
  • No other open PR covers this slice. #1908 (merged) hardened bounds in the generator, this one only touches the CLI layer.

Commands run locally (Linux, pefile + iced-x86 in a throwaway venv)

  • python3 -B tests/bink_heap_aot_check.py: 12 tests OK
  • python3 -B tests/bink_heap_aot_cli_check.py: 8 tests OK
  • python3 tests/docs_links_check.py: OK
  • python3 tests/bidi_controls_check.py: OK
  • git diff --check origin/main...HEAD: clean
  • Mutations of the code under test, each makes the new suite fail, then reverted:
    • drop mkdir(parents=True): 1 failure
    • drop the temp-file cleanup: 1 failure
    • disable the symlink-output refusal: 2 failures
    • weaken the negative --entries check: 1 failure

Not covered by this review: Windows run (CMake registration is exercised only by the Windows CTest run).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6066501494 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2627#pullrequestreview-6066501494). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T23:37:29Z. **Review:** COMMENTED --- Review of head e766269c (comment only). Result: sound, no blocking findings. What I checked - `tools/bink_heap_aot.py`: `_validate_args` runs before `generate()`; `_write_atomic` writes a sibling temp file and replaces it, and removes the temp file on any failure. `main()` now returns 0 and exits via `SystemExit(main())`. The old suffix/same-path check is kept, now with a hardlink `samefile` check too. - `tests/bink_heap_aot_cli_check.py` is registered in `CMakeLists.txt` next to `bink_heap_aot_check`, with a 60 s timeout. The existing suite is untouched. - No other open PR covers this slice. #1908 (merged) hardened bounds in the generator, this one only touches the CLI layer. Commands run locally (Linux, pefile + iced-x86 in a throwaway venv) - `python3 -B tests/bink_heap_aot_check.py`: 12 tests OK - `python3 -B tests/bink_heap_aot_cli_check.py`: 8 tests OK - `python3 tests/docs_links_check.py`: OK - `python3 tests/bidi_controls_check.py`: OK - `git diff --check origin/main...HEAD`: clean - Mutations of the code under test, each makes the new suite fail, then reverted: - drop `mkdir(parents=True)`: 1 failure - drop the temp-file cleanup: 1 failure - disable the symlink-output refusal: 2 failures - weaken the negative `--entries` check: 1 failure Not covered by this review: Windows run (CMake registration is exercised only by the Windows CTest run). 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:38:12Z.


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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target cpu_bink_descriptors_lifted cpu_bink_frame_to_heap_objects cpu_bink_heap_lifted -- -j 2): 0.87s (configure 2.27s)
    • Test (ctest --preset dev -R 'bink_heap_aot' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (6.41s: bink_heap_aot_check 1.45s, runtime_bink_heap_aot_cli_check 6.26s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target cpu_bink_descriptors_lifted cpu_bink_frame_to_heap_objects cpu_bink_heap_lifted -- -j 2): 6.42s (configure 2.32s)
    • Test (ctest --preset release -R 'bink_heap_aot' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (6.48s: bink_heap_aot_check 1.38s, runtime_bink_heap_aot_cli_check 6.33s)
  • sccache: 61/64 hits; wall 24.2s
    AI-assisted; commands listed were executed locally.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7177839909 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2627#issuecomment-7177839909). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T23:38:12Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `e766269c43789d5d67cc0dd1a366bfbe76bd89cc`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target cpu_bink_descriptors_lifted cpu_bink_frame_to_heap_objects cpu_bink_heap_lifted -- -j 2`): `0.87s` (configure `2.27s`) - Test (`ctest --preset dev -R 'bink_heap_aot' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`6.41s`: `bink_heap_aot_check` `1.45s`, `runtime_bink_heap_aot_cli_check` `6.26s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target cpu_bink_descriptors_lifted cpu_bink_frame_to_heap_objects cpu_bink_heap_lifted -- -j 2`): `6.42s` (configure `2.32s`) - Test (`ctest --preset release -R 'bink_heap_aot' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`6.48s`: `bink_heap_aot_check` `1.38s`, `runtime_bink_heap_aot_cli_check` `6.33s`) - `sccache`: 61/64 hits; wall `24.2s` 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!2619
No description provided.