runtime: extract main(argv), bounds validation, and struct.error guards in resource_root with CLI suite #2535
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2543"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T20:24:24Z.
Change
Harden the
tools/resource_root.pyCLI entrypoint and argument/error validation, and add a standalone pure-Python CLI/mutation test suite (tests/resource_root_cli_check.py, registered asruntime_resource_root_cli_checkinCMakeLists.txt):main(argv: Sequence[str] | None = None) -> intto forwardargvtoparser.parse_args(argv)and return0, invokingraise SystemExit(main())underif __name__ == "__main__".--offset >= 0,--stored > 0,--decoded > 0, andarchiveis not a directory before opening the file.struct.errorin the caught exception set(OSError, ValueError, struct.error, zlib.error)so malformed/truncated resource errors exit cleanly viaparser.exit(1, f"{args.archive}: {error}\n")with zero raw tracebacks while preserving the exact JSON stdout (root_type_hash,root_bytes) contract.AI-assisted.
Verification
Verified on commit
83362d09f08561202c4b5753135bed6e0340d84d(rebased ontoupstream/main5a219a3c) usingout\pe-env\Scripts\python.exe -B:out\pe-env\Scripts\python.exe -B tests/resource_root_cli_check.py -v-> exit 0 (Ran 10 tests in 3.494s,OK)out\pe-env\Scripts\python.exe -B tests/resource_root_check.py -v-> exit 0 (Ran 5 tests in 0.442s,OK)out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py-> exit 0 (form coverage checks passed)out\pe-env\Scripts\python.exe -B tests/docs_links_check.py-> exit 0 (Self-test passed. Checked 19 Markdown files and 479 links.)out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py-> exit 0 (Self-test passed. Checked 1778 tracked source, script and build/CI files: no bidirectional controls.)tools/resource_root.py(parse_args(argv)forwarding,--offset < 0,--stored <= 0->< 0,--decoded <= 0->< 0,archive.is_dir(),struct.errorguard,zlib.errorguard,return 0, exact 2 MiB budget boundary) causedtests/resource_root_cli_check.pyto fail (exit 1).Evidence and follow-up
tests/resource_root_cli_check.pyare synthetic in-memory relocated PRD0 v0x7a zlib streams generated in Python with synthetic type hashes (0x1234abcd,0x00008888) under the repository MIT License.--offset/--stored/--decoded, exact 2 MiB decoded boundary,main(None)sys.argvforwarding,runpy__main__entrypoint, and exact JSON schema.--offset, zero/negative--stored/--decoded,> 2 MiBstored/decoded budget, corrupt zlib andzlib.errorguard, truncated/malformed PRD0 andstruct.errorguard, and Python 3.14argparse-compatible usage errors.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:38:49Z.
Review: COMMENTED
Review of head
83362d09(comment only, no approval).No blocking findings. Checked:
tools/resource_root.py:main(argv)forwards toparse_args, returns 0 and is wrapped inraise SystemExit(main()). Upfront checks for negative--offset, non-positive--stored/--decoded, and directory archive.struct.errorjoins the caught set, so malformed input exits 1 throughparser.exitinstead of a traceback. JSON stdout contract is unchanged.tests/resource_root_cli_check.py(10 tests) guards these behaviors through the CLI. Registered asruntime_resource_root_cli_check.resource_root.Commands run locally (Linux, pefile venv, 10 commits behind main):
python3 -B tests/resource_root_cli_check.py-> OKpython3 -B tests/resource_root_check.py-> OKpython3 tests/docs_links_check.py-> passedpython3 tests/bidi_controls_check.py-> passedgit diff --check origin/main...HEAD-> cleanstruct.error(1 error);--storedcheck<= 0to< 0(3 failures); disable the directory check (1 failure).A Windows Server 2025 run on the current head follows separately.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:45:42Z.
Win2025 WARP receipt for head
1c984af0after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
1c984af05d639e796b2560b666c708f6892e9109:--preset dev):cmake --build --preset dev -- -j 2):78.96s(configure2.35s)ctest --preset dev -R '^(runtime_resource_root_cli_check|resource_root.*)$' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (5.90s:runtime_resource_root_cli_check5.70s)/O2(--preset release):cmake --build --preset release -- -j 2):87.66s(configure2.10s)ctest --preset release -R '^(runtime_resource_root_cli_check|resource_root.*)$' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (4.89s:runtime_resource_root_cli_check4.77s)tests/resource_root_cli_check.pyok (5.2s),tests/resource_root_check.pyok (0.8s)sccache: 187/568 hits; wall188.8sAI-assisted; commands listed were executed locally.