tooling: validate positive interval bounds in range_manifest and add unit and CLI suite #2086
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2093"
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-25T00:11:43Z.
Change
Validate function names and positive interval bounds in
tools/range_manifest.py, extract a testablemain(argv=None) -> intwith atomic temp-file writes, and add a pure-Python unit and CLI test suite (tests/range_manifest_check.py) registered inCMakeLists.txt(range_manifest_check):manifest()rejects emptynames, empty/blank/non-string function names, duplicate function names, and empty/inverted intervals (end <= start) withValueErrorwhile preservingmap_symbols()and the existing JSON schema (image_sha256,functions).main(argv=None) -> intwith_write_atomic_text()(temp file in output parent +os.replace, unlinking the temp file on any error so failures never corrupt an existing manifest or leave leftover temp files) andparser.exit(1, ...)on(ValueError, OSError)with zero raw tracebacks.tests/range_manifest_check.pycovering synthetic MSVC/MAPparsing (preferred load address, RVA subtraction,setdefaultfirst-symbol precedence), binary image SHA-256, CLI JSON output (direct and subprocess), and negative controls pinningValueError/SystemExit(1)and zero temp-file leaks on missing load address, missing symbol/_end,end == start,end < start, empty/blank/duplicate names, missing files, and failedos.replace.Verification
Tested on commit
02c31a29(rebased ontoupstream/main75b25ad0, Windows x64, Python viaout/pe-env):.\out\pe-env\Scripts\python.exe -B tests/range_manifest_check.pyRan 6 tests in 0.204s—OK(exit 0)..\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.pyform coverage checks passed(exit 0)..\out\pe-env\Scripts\python.exe -B tests/docs_links_check.pySelf-test passed. Checked 18 Markdown files and 393 links.(exit 0)..\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.pySelf-test passed. Checked 1414 tracked source, script and build/CI files: no bidirectional controls.(exit 0).Note: No C++ targets were modified;
range_manifest_checkis pure Python and registered next tobink_descriptors_aot_checkinCMakeLists.txt.Evidence and follow-up
tests/range_manifest_check.pyare synthetic in-memory MSVC/MAPtext and small byte buffers; no external binaries or game files are used.ValueErrormessages andSystemExit(1)exit codes with zero raw tracebacks, preserved target files onos.replacefailure, and zero leftover temp files.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T00:23:16Z.
Ran it, broke the validator seven ways — all caught — and one side effect I would rather you hear from me than from CI
if not names:removed (empty name list accepted)name.strip()dropped (blank name accepted)end <= start→end < start(allows a zero-length range)os.replace(tmp_path, output)→output.write_text(...)(non-atomic)mainreturns 1 instead of 0The fourth and the sixth are the two I would have expected to slip: the boundary
end == startis the one an interval validator usually getswrong, and "atomic write" is the kind of property that is easy to state and hard to check. Both are pinned.
Two things the implementation gets right that the mutations confirm indirectly:
dir=str(output.parent)), which is what makesos.replaceatomic across the rename;except BaseExceptionpath unlinks the temp file, and no.tmpfile is left behind after a successful write — I checked the directorycontents after the call.
The side effect: the output file's mode changes on POSIX
On Windows this machine reports
0666for both the atomic writer and the plainwrite_textpath, so nothing to see here:On POSIX it is not the same.
tempfile.mkstempopens the file with mode 0600 regardless of umask, andos.replacecarries that modeto the output.
Path.write_textfollows the umask instead (typically0644). So this PR silently changes the permissions of arange-manifest.jsonproduced on Linux from0644to0600— and CI runs on Linux, so the first place that shows up is a later step reading thefile as a different user, or a packaging step that copies it into an image.
I could not measure this here (Windows only), so treat it as a claim about the standard library's contract rather than a measurement. If you want to
keep the old behaviour, one line after
mkstemppreserves it:Alternatively, if the manifest is only ever read by the invoking user, say so in the docstring and this becomes a non-issue — but that is the sort of
thing worth writing down while the change is small.
One smaller question
manifest()now raises for an emptynames. The CLI passesargs.names; if that argument is optional, a caller who used to get an emptyfunctions: []document now gets aValueError. That is probably the intent (an empty manifest is a bug), but it is a behaviour change for existingcallers — worth a line in the description, since the title frames this as validation of bounds.
What I did not check
Anything that needs a real PE image and map file: I exercised the check and the helpers it covers, not
manifest()against a fixture pair. The6 testsyou wrote presumably do; my mutations were aimed at the guards they should be protecting.AI-assisted; the seven mutations and the mode probe were run locally on Windows 11 build 26300.9974.