script: extract main(argv) and guard malformed RPF9/PSIN inputs in script_state_probe with unit suite #2344
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2352"
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-25T13:19:29Z.
Change
Extract
main(argv: list[str] | None = None) -> intintools/script_state_probe.py, harden malformed RPF9/PSIN input handling, and add a pure-Python unit and CLI validation suite (tests/script_state_probe_check.py, registered asscript_state_probe_checksinCMakeLists.txt):argvtoparser.parse_args(argv)and return exit code0on success (if __name__ == "__main__": raise SystemExit(main())).os.fstat(stream.fileno()).st_size == 0beforemmap.mmapininspect()so empty files raiseValueError("Empty archive; expected an RPF9 archive")instead of an unhandledmmaperror.(OSError, ValueError, struct.error, zlib.error)inmain()viaparser.exit(1, ...)so missing paths, directories, empty files, bad magic, malformed RPF9/PSIN trees, and decode errors exit cleanly with code1and zero raw tracebacks.Verification
Verified on commit
b38bef1f(based onupstream/main214ed093):out/pe-env/Scripts/python.exe -B tests/script_state_probe_check.py -v->Ran 7 tests in 0.251s/OK(exit 0)out/pe-env/Scripts/python.exe -B tests/script_state_check.py->Ran 22 tests in 0.849s/OK(exit 0)out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py->form coverage checks passed(exit 0)out/pe-env/Scripts/python.exe -B tests/docs_links_check.py->Self-test passed. Checked 19 Markdown files and 457 links.(exit 0)out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py->Self-test passed. Checked 1642 tracked source, script and build/CI files: no bidirectional controls.(exit 0)Evidence and follow-up
tests/script_state_probe_check.pyare synthetic in-memoryRPF9archives with 16-byte-aligned zlib-compressedPSIN/LSCH/LENM/LSNS/LGID/LRSC/CHKSrecords.joaat(),literal(),verified_camera(),tree_arrays(),inspect_tree(),inspect()(single witness vs ambiguous multi-candidate), missing/directory/0-byte archives (verifyingmmap.mmapis never called on 0-byte files), bad magic, corrupt zlib, invalidCHKSlength/total, badLRSCmagic/directory sizes, bad root ID, invalid instance marker, truncated schema members, duplicate/non-label state IDs, andstruct.error/zlib.errorCLI exit handling.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:20:49Z.
Review: COMMENTED
Review of head
b38bef1f452763d820b20f8bc434bb7410ec8d2a(comment only).Summary: Small, safe change.
main(argv)is extracted, an empty-file guard is added, andstruct.error/zlib.errorare now reported as clean exit-1 errors. A 7-test unit suite is registered in CTest asscript_state_probe_checks. No P1 or P2 findings.Checks (run locally on the PR worktree):
python3 -B tests/script_state_probe_check.py: Ran 7 tests, OKpython3 tests/docs_links_check.py: self-test passed, 19 files and 457 links checkedpython3 tests/bidi_controls_check.py: no bidirectional controls in 1642 filesgit diff --check origin/main...HEAD: cleanMutations (both killed by the suite):
except (OSError, ValueError, struct.error, zlib.error)back to(OSError, ValueError)gaveFAILED (errors=2).st_size == 0changed to== -1) gaveFAILED (failures=1).The worktree was reverted after each mutation.
Nits (non-blocking):
tools/script_state_probe.py(inspect): the explicit empty-file check duplicates whatmmapwould reject with its ownValueError. It is still useful because it gives a clearer message.No Windows/WARP run was needed. There is no shader or C++ change.
AI-assisted; commands listed were executed locally.