bcpack: extract main(argv) and add regular-file and packet size guards in bcpack_symbols with CLI suite #2596

Merged
Ammmae0x merged 1 commit from upstream-pr/2604 into main 2026-11-25 23:04:26 +00:00
Ammmae0x commented 2026-11-25 22:57:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T22:57:55Z.


Summary

  • Extracted main(argv: list[str] | None = None) -> int in tools/bcpack_symbols.py returning 0 on success with raise SystemExit(main()) under __main__.
  • Factored lane-shape validation into shared _validate_shape(alphabet_bits, symbols) and added upfront stat() + stat.S_ISREG + 1 <= st_size <= MAX_INPUT packet guards before open(), while preserving existing tests/bcpack_symbols_check.py caller stderr and exit-1 contracts.
  • Added standalone pure-Python CLI test suite tests/bcpack_symbols_cli_check.py (direct main(argv), valid single/multi-lane and exact MAX_INPUT packets, upfront no-open missing/directory/empty/oversize guards, width/symbol bounds, trailing non-zero and corrupt packet refusals, and Python 3.14-safe argparse error checks) and registered bcpack_symbols_cli_check in CMakeLists.txt with TIMEOUT 60.

Verification

Rebased cleanly onto upstream/main (f03cf16f, commit af82faaa) and verified:

python -B tests/bcpack_symbols_cli_check.py -v
-> Ran 5 tests in 0.667s — OK

python -B tests/bcpack_symbols_check.py -v
-> Ran 10 tests in 1.402s — OK

python -B tests/form_coverage_check.py
-> form coverage checks passed

python -B tests/docs_links_check.py
-> Self-test passed. Checked 19 Markdown files and 499 links.

python -B tests/bidi_controls_check.py
-> Self-test passed. Checked 1839 tracked source, script and build/CI files: no bidirectional controls.

Adversarial mutation audit in an isolated temp copy killed 13/14 targeted mutations across regular-file, size-bound, validation-order, trailing-byte, order-trace, exit-code, argv-passthrough, boolean-type, and lane-shape guards.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6615465718 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2604). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T22:57:55Z. --- ## Summary - Extracted `main(argv: list[str] | None = None) -> int` in `tools/bcpack_symbols.py` returning `0` on success with `raise SystemExit(main())` under `__main__`. - Factored lane-shape validation into shared `_validate_shape(alphabet_bits, symbols)` and added upfront `stat()` + `stat.S_ISREG` + `1 <= st_size <= MAX_INPUT` packet guards before `open()`, while preserving existing `tests/bcpack_symbols_check.py` caller stderr and exit-1 contracts. - Added standalone pure-Python CLI test suite `tests/bcpack_symbols_cli_check.py` (direct `main(argv)`, valid single/multi-lane and exact `MAX_INPUT` packets, upfront no-`open` missing/directory/empty/oversize guards, width/symbol bounds, trailing non-zero and corrupt packet refusals, and Python 3.14-safe argparse error checks) and registered `bcpack_symbols_cli_check` in `CMakeLists.txt` with `TIMEOUT 60`. ## Verification Rebased cleanly onto `upstream/main` (`f03cf16f`, commit `af82faaa`) and verified: ```text python -B tests/bcpack_symbols_cli_check.py -v -> Ran 5 tests in 0.667s — OK python -B tests/bcpack_symbols_check.py -v -> Ran 10 tests in 1.402s — OK python -B tests/form_coverage_check.py -> form coverage checks passed python -B tests/docs_links_check.py -> Self-test passed. Checked 19 Markdown files and 499 links. python -B tests/bidi_controls_check.py -> Self-test passed. Checked 1839 tracked source, script and build/CI files: no bidirectional controls. ``` Adversarial mutation audit in an isolated temp copy killed 13/14 targeted mutations across regular-file, size-bound, validation-order, trailing-byte, order-trace, exit-code, argv-passthrough, boolean-type, and lane-shape guards. AI-assisted.
tedin7 commented 2026-11-25 23:02:02 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head af82faaa (0 commits behind main). Verdict: sound, no blocking findings.

Checked:

  • tools/bcpack_symbols.py: _validate_shape is a pure extraction of the old checks in decode(), same messages. main(argv) now stats the packet first, refuses non-regular files and sizes outside 1..MAX_INPUT before open(), then validates shape. Errors still go through parser.exit(1, "BCPack symbols: ..."). decode() keeps its own size check, so the library path is unchanged.
  • No other open or merged PR covers this slice (#1831 pinned input type/result keys/CLI failures and is already merged; this adds the guards and a direct main(argv) suite).
  • Test tests/bcpack_symbols_cli_check.py is registered in CMake with TIMEOUT 60 next to the sibling bcpack_symbols_check.

Commands run (worktree on the exact head):

  • python3 -B tests/bcpack_symbols_cli_check.py -> OK (5 tests)
  • python3 -B tests/bcpack_symbols_check.py -> OK
  • python3 tests/docs_links_check.py -> passed
  • python3 tests/bidi_controls_check.py -> passed
  • git diff --check origin/main...HEAD -> clean
  • Mutations, each made the new suite fail (1 failure): removed the S_ISREG guard; removed the st_size range guard; changed return 0 to return 1.

Python-only change, so no GPU/game behavior is involved.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6066164870 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2604#pullrequestreview-6066164870). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T23:01:53Z. **Review:** COMMENTED --- Review of head af82faaa (0 commits behind main). Verdict: sound, no blocking findings. Checked: - `tools/bcpack_symbols.py`: `_validate_shape` is a pure extraction of the old checks in `decode()`, same messages. `main(argv)` now stats the packet first, refuses non-regular files and sizes outside 1..MAX_INPUT before `open()`, then validates shape. Errors still go through `parser.exit(1, "BCPack symbols: ...")`. `decode()` keeps its own size check, so the library path is unchanged. - No other open or merged PR covers this slice (#1831 pinned input type/result keys/CLI failures and is already merged; this adds the guards and a direct `main(argv)` suite). - Test `tests/bcpack_symbols_cli_check.py` is registered in CMake with TIMEOUT 60 next to the sibling `bcpack_symbols_check`. Commands run (worktree on the exact head): - `python3 -B tests/bcpack_symbols_cli_check.py` -> OK (5 tests) - `python3 -B tests/bcpack_symbols_check.py` -> OK - `python3 tests/docs_links_check.py` -> passed - `python3 tests/bidi_controls_check.py` -> passed - `git diff --check origin/main...HEAD` -> clean - Mutations, each made the new suite fail (1 failure): removed the `S_ISREG` guard; removed the `st_size` range guard; changed `return 0` to `return 1`. Python-only change, so no GPU/game behavior is involved. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 00:00:54 +00:00
tedin7 commented 2026-11-26 00:01:09 +00:00 (Migrated from github.com)

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


Win2025 WARP receipt for head af82faaa (Python-only PR; both bcpack_symbols suites run).

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

  • Windows Python checks: tests/bcpack_symbols_check.py ok (1.9s), tests/bcpack_symbols_cli_check.py ok (0.8s)
  • Wall: 12.8s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7177080835 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2604#issuecomment-7177080835). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T23:02:39Z. --- Win2025 WARP receipt for head af82faaa (Python-only PR; both bcpack_symbols suites run). Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `af82faaaa387bbd0e1b0717285f7ea997adb0c88`: - **Windows Python checks**: `tests/bcpack_symbols_check.py` ok (`1.9s`), `tests/bcpack_symbols_cli_check.py` ok (`0.8s`) - Wall: `12.8s` AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 00:01:09 +00:00 (Migrated from github.com)

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


Win2025 WARP receipt for head af82faaa.

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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 2.09s (configure 2.52s)
    • Test (ctest --preset dev -R 'bcpack_symbols' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (1.12s: bcpack_symbols_cli_check 0.99s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 3.10s (configure 2.55s)
    • Test (ctest --preset release -R 'bcpack_symbols' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (0.95s: bcpack_symbols_cli_check 0.83s)
  • Windows Python checks: tests/bcpack_symbols_check.py ok (1.8s), tests/bcpack_symbols_cli_check.py ok (0.8s)
  • sccache: 18/28 hits; wall 23.8s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7177111746 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2604#issuecomment-7177111746). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T23:04:15Z. --- Win2025 WARP receipt for head af82faaa. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `af82faaaa387bbd0e1b0717285f7ea997adb0c88`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev -- -j 2`): `2.09s` (configure `2.52s`) - Test (`ctest --preset dev -R 'bcpack_symbols' --parallel 2 --no-tests=error --output-on-failure`): **1/1 passed** (`1.12s`: `bcpack_symbols_cli_check` `0.99s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release -- -j 2`): `3.10s` (configure `2.55s`) - Test (`ctest --preset release -R 'bcpack_symbols' --parallel 2 --no-tests=error --output-on-failure`): **1/1 passed** (`0.95s`: `bcpack_symbols_cli_check` `0.83s`) - **Windows Python checks**: `tests/bcpack_symbols_check.py` ok (`1.8s`), `tests/bcpack_symbols_cli_check.py` ok (`0.8s`) - `sccache`: 18/28 hits; wall `23.8s` 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!2596
No description provided.