pe: sort package scan and harden CLI path guards in pe_package_preflight with CLI suite #2601
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2609"
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-25T23:18:13Z.
Change
Make PE package discovery deterministic and harden CLI path validation in
tools/pe_package_preflight.py, and add a synthetic PE32+ CLI/error test suite intests/pe_package_preflight_cli_check.py(registered aspe_package_preflight_cli_checkinCMakeLists.txtwithTIMEOUT 60):_paths(root)deterministically usingkey=lambda p: (p.as_posix().casefold(), p.as_posix())so image-count and total-byte cutoffs do not depend on filesystem traversal order.root.is_dir()and non-emptyentryupfront beforeinspect(), and validate--outputbefore temp staging (reject symlinks, non-directory parent/ancestors, directories/empty path, and paths inside the inspected package).struct.erroralongside(OSError, ValueError, KeyError, pefile.PEFormatError)cleanly on stderr with exit code 1 and no tracebacks, preserving existing tests and message strings.AI-assisted.
Verification
Tested on commit
fbc33e67(rebased onupstream/main) without\pe-env\Scripts\python.exe -B:out\pe-env\Scripts\python.exe -B tests\pe_package_preflight_check.py -v: 14 tests OK (exit 0).out\pe-env\Scripts\python.exe -B tests\pe_package_preflight_cli_check.py -v: 8 tests OK (exit 0), covering stdout and atomic--outputwith 0 leftover temps,sys.argv/__main__entrypoint, unsortedrglobdeterministic ordering and cutoff,root.is_dir()/ blankentryrejection,--outputparent-file/directory/symlink/inside-package rejections before temp staging, atomic replace failure cleanup, invalid PE / missing entry, and Python 3.14-safeargparseerrors._pathssort,_validate_entry,output.is_symlink(), parent-not-directory check, andoutput.is_dir()); 5/5 mutations killed bytests\pe_package_preflight_cli_check.pyand 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 PE32+ fixtures in
tests/pe_package_preflight_cli_check.pyare synthetically generated in-memory withstruct(MIT License). No CLI flags, JSON schema, or build prerequisites changed.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:30:05Z.
Review: COMMENTED
Review of head
fbc33e67(comment only).Checked against origin/main:
_paths, the upfrontis_dir()and entry checks,_validate_output(symlink, non-directory ancestor, directory, inside-package) and the addedstruct.errorcatch are correct. Error messages and exit code 1 stay as before; no tracebacks.pe_package_preflight.pe_package_import_closure, as expected.Commands run (Linux,
pefilein a throwaway venv):tests/pe_package_preflight_check.py: 14 OKtests/pe_package_preflight_cli_check.py: 8 OKpython3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEAD: cleanNo blocking findings. Windows dev+release run to follow before any merge.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:31:14Z.
Win2025 WARP receipt for head
623bf8b0after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
623bf8b06becc39d209b97eec24808d9ca908b00:--preset dev):cmake --build --preset dev -- -j 2):15.25s(configure2.08s)ctest --preset dev -R 'pe_package_preflight_cli_check|pe_package_import_closure' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (4.74s:pe_package_import_closure0.86s,pe_package_preflight_cli_check4.62s)/O2(--preset release):cmake --build --preset release -- -j 2):12.66s(configure1.90s)ctest --preset release -R 'pe_package_preflight_cli_check|pe_package_import_closure' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (4.25s:pe_package_import_closure0.95s,pe_package_preflight_cli_check4.13s)tests/pe_package_preflight_check.pyok (0.8s),tests/pe_package_preflight_cli_check.pyok (4.5s)sccache: 24/68 hits; wall46.8sAI-assisted; commands listed were executed locally.