pe: validate package plan edges and add pe_run_package unit checks #1886
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1893"
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-24T20:26:14Z.
Change
Harden input and graph-edge validation in
tools/pe_run_package.pyand add pure-Python unit and CLI refusal coverage intests/pe_run_package_plan_check.py, registered inCMakeLists.txtaspe_run_package_plan_check:plan()withValueErrorinstead of raisingIndexErroronchain[-1].plan()withValueErrorinstead of raisingIndexErroronorder[-1]..,.., and path separators intrap_key()DLL names and validate#ORDINALsuffixes (1..65535ASCII digits) so malformed ordinals fail deterministically beforerun()..,.., and path separators in--systemprovider names inmain().is_host_create_thread()contracts,trap_key()positive/negative cases,plan()edge rejections (empty graph, empty chain, cycle, self-import, entry-as-dependency, conflicting bindings, strictforwarded_external_unverified), and CLI refusal paths without tracebacks.Verification
Verified on commit
9a06df39:ctest --preset dev -E "cpu_native_archive_" -R "^(pe_package_ordinal_plan|pe_package_import_closure|pe_run_package_invalid_pe|pe_run_package_plan_check|pe_host_commit_preflight|xgameruntime_preflight_stub_refused|pe_run_package_trap_missing)$" --output-on-failure: 7/7 passed (Total Tests: 1154).ctest --preset release -E "cpu_native_archive_" -R "^(pe_package_ordinal_plan|pe_package_import_closure|pe_run_package_invalid_pe|pe_run_package_plan_check|pe_host_commit_preflight|xgameruntime_preflight_stub_refused|pe_run_package_trap_missing)$" --output-on-failure: 7/7 passed (Total Tests: 1154).python -B tests/pe_run_package_plan_check.py -v: 11/11 passed.python -B tests/form_coverage_check.py: passed.python -B tests/docs_links_check.py: passed (18 Markdown files, 376 links).python -B tests/bidi_controls_check.py: passed (1330 tracked files).Evidence and follow-up
All new test fixtures in
tests/pe_run_package_plan_check.pyare synthetic in-memory reports and minimal synthetic PEs generated viacompat_report_check.build_image. Running the new test suite against unpatchedupstream/main:tools/pe_run_package.pyfailed with 6 failures and 2 errors on the newly added edge-validation cases.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T20:53:18Z.
I fixed one parser edge on this branch: a zero-padded ordinal was accepted, but its spelling did not match the canonical import-route key. The parser now normalizes it and rejects an oversized decimal before converting it to int. The eleven source-built plan/CLI tests passed with the new padded, zero and long-ordinal cases.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:06:40Z.
Review: COMMENTED
Review of #1893, exact SHAs: first commit
9a06df3916f2e5c81ebc23917c76f71764fae845and final headc3b05e453e047c555845fc395e91c6a708183dd2(the PR was already MERGED when I finished, so this is a post-merge comment).Verdict: no P1. One P2 (test is not runnable on Linux), merge was reasonable.
Diff read
tools/pe_run_package.py: empty-chain and empty-graph refusals inplan(), strictertrap_key()(dot names, slashes, ordinal range 1..0xFFFF, leading zeros normalised to#42in the last commit), stricter--systembasenames. Each refusal replaces anIndexError/ silent accept; semantics look right, no off-by-one in the 0xFFFF bound (#65535accepted,#65536and#0refused).CMakeLists.txt: oneadd_testinside theINTAKE_PYTHON(Windows pe-env) block.P2:
test_cli_refusal_paths_without_tracebacksfails on Linux, casepin-shim without shimtests/pe_run_package_plan_check.py(thecaseslist, the--pin-shim kernel32.dll --preflight-onlyrow). The checkset(pin_shims) - shims.keys()lives inrun()attools/pe_run_package.py:144, afterC.WINFUNCTYPE(line 137) andC.WinDLL. On a non-Windows host the tool dies withAttributeError: module 'ctypes' has no attribute 'WINFUNCTYPE'and a Traceback, so the test asserts "no Traceback" and fails. The test header says "pure-Python controls", but this one case is not. It passes on Windows (see below) and CMake only registers it under the Windows pe-env, so CI is not hurt. Fix options: move the--pin-shim/--shimvalidation intomain()beforerun(), or skip that row whensys.platform != "win32".P3 (nit)
The
1 <= len(ordinal) <= 5guard added in the last commit is not independently pinned by a test: Python's int-digit limit already raisesValueErrorfor the 5000-digit case, so removing the guard keeps the suite as it is (it only affects the message). Harmless.Commands run locally (Linux, venv python
/root/.local/share/x2w-rev-venv/bin/python)git diff --check origin/main...HEAD: clean at both SHAs.tests/pe_run_package_plan_check.py: 11 tests, 10 pass, 1 FAIL (the P2 above), same at9a06df39andc3b05e45.pe_run_package_invalid_check.py,pe_package_ordinal_plan_check.py,pe_package_preflight_check.py,host_commit_check.py,intake/import_forms_check.py,bidi_controls_check.py: rc=0.docs_links_check.py: "Checked 18 Markdown files and 376 links".trap_missing_check.pyandxgameruntime_preflight_check.pyneed built exe arguments, not run on Linux.c3b05e45:cteston^(pe_run_package_plan_check|pe_run_package_invalid_pe|pe_package_ordinal_plan|pe_host_commit_preflight)$passed 4/4 in Debug and Release,import_forms_check.pyok.Mutations (all reverted with
git checkout -- .)if not chain->if False)test_plan_refuses_empty_resolution_chainerrorsif not order->if False)test_plan_refuses_empty_reachable_grapherrors0xFFFF->0xFFFFF(at9a06df39)#65536case"/"/"\\"checks intrap_keydir\\user32.dll!MessageBoxWcase.lstrip("0")(atc3b05e45)symbol = "#" + ordinalnormalisation1 <= len(ordinal) <= 5AI-assisted; commands listed were executed locally.