tooling: add a hash-gated patch manifest loader #3056
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3056
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3056"
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?
@Not-Saii on GitHub · 2026-11-27 12:32 UTC · original
Not-Saii:tooling/patch-manifest-loader→main· +313 −0 · 5 files · 2 commits · merged 2026-11-27 13:26 UTCRefs #3037 (item 1: schema, loader and hash gate). Items 2-4 stay open.
What changes
tools/patch_manifest.pyreads a TOML manifest with the standard library'stomllib. It validates the whole manifest, then refuses it unless the input file's SHA-256 equals[target] input_sha256(manifest is for another input). Nothing is returned before both pass, so there is no partial apply.[[patch]]needs a uniqueid, akind, and non-emptywhyandremove_when. Unknown and missing keys are refused at every level, so a misspelled key fails instead of being ignored.kind = "memory"is defined:rva(integer below 2^32),expect_sha256(hash of the original bytes, never the bytes) andbytes(lowercase hex). The fields are checked for shape only, and two memory patches may not overlap. Nothing applies them yet; that is item 2.hookanddataare refused asnot supporteduntil their stages define them.manifest_sha256(over the manifest file's bytes) and the patch ids, for item 4's run reports.docs/experiments/patch-manifests.md. The README is unchanged because no applier exists yet.Fixture
tests/patch_manifest_check.pybuilds a synthetic PE32+ at run time withbuild_pe32_plusfromtests/call_evidence_check.py. No binaries are committed. It is registered for Linux CI intests/checks/python-linux/patch_manifest.txtand as CTestpatch_manifest_controls.p001.manifest is for another inputand empty stdout.hook, a missingwhy, a blankremove_when, a duplicate id, overlapping patches, odd-lengthbytes, a booleanrva, an upper-caseinput_sha256, no patches, and a TOML syntax error are each refused.Tested
Commit
500cc76fonmain232ae71e, Windows 11 build 26300, Python 3.14:Not run locally on Linux; the
python-linuxjob runs the check on Python 3.12. CTest registration was not exercised locally (no configure run).🤖 Generated with Claude Code
@R0Y00 on GitHub · 2026-11-27 13:10 UTC · original · requested changes
I tested
500cc76fwith synthetic TOML. Akindvalue of["memory"]raisesTypeError: unhashable type: 'list'; an inline table raises the equivalentdicterror. The CLI catchesValueErrorandOSError, so both escape as tracebacks instead of the normal manifest diagnostic. Please validate thatkindis a string before looking it up and add a wrong-type control.The range check also accepts a two-byte replacement at
0xffffffffand hands the planner a span ending at0x100000001. Since every byte of a memory patch must have a representable RVA, please validate the entire span. The one-byte case at0xffffffffis the adjacent shape control and should remain valid at this stage; matching it to an actual mapped section belongs to the runtime stage.@Not-Saii on GitHub · 2026-11-27 13:14 UTC · original
Thanks, both are fixed in
ec7d1e51.kindtype: it must now be a string before it is looked up. A list or inline-tablekindis refused askind [...] is not supported. New controls cover both shapes inparse, plus one through the CLI that expects exit 1, thepatch manifest:message and no traceback.0xffffffffis refused withspan [0xffffffff, 0x100000001) does not fit in 32-bit RVAs. The 1-byte patch at0xffffffffstill loads and is kept as the edge control. Checking against mapped sections stays with the runtime stage.Mutations, each run separately:
kindremovedTypeError, and the CLI case sees a traceback.>=)python -B tests/patch_manifest_check.py: 3 tests OK on Windows 11 build 26300, Python 3.14.docs_links_checkandbidi_controls_checkpass.docs/experiments/patch-manifests.mdlists the new rules and controls.@R0Y00 on GitHub · 2026-11-27 13:26 UTC · original · approved these changes
Retested
ec7d1e51integrated withmaindb28a796(tree1dc1147760082db546e64a48c7b4e6702ac17a47).python -B tests/patch_manifest_check.pypassed all three tests, including the wrong-input hash control, and the docs link check passed. The standalone CLI returned the manifest diagnostic with exit 1 for a list kind, an inline-table kind, and a two-byte patch at0xffffffff, with no traceback. A one-byte patch at0xffffffffreturned the expected plan. Both review findings are addressed.