Repository navigation
tooling: extend the patch manifest loader (nesting refusal, shader kind, load_data) - #3119
Conversation
|
Independent audit of the fixture's coverage on Not a code change; measurements only. Environment
CommandsEach mutation below is applied alone, as a single Observed — 24 mutations, 16 killed
The mutation table in The eight survivors, each with its witnessRun on the same manifest, head versus mutant in place.
Patch adjacency and ordering (lines 165–167).
The memory patch's output field is unpinned. Removing The CLI's What this does not say
AI-assisted. |
…e CLI's OSError Four memory patches in descending RVA, three adjacent and one at RVA 0, load; a one-byte overlap is refused in either order. A hash or key with trailing text and an empty bytes are refused, the bound patch is compared field by field, and a missing input file reaches the CLI as a diagnostic. Each kills one of the eight mutations that survived the fixture.
|
Thank you for the audit, @thepatrickworld. I re-ran your 24 mutations at I pushed two commits to this branch:
With them, all 24 mutations are killed. This comment was AI-assisted. |
|
Independent re-run on What was measuredThe 24 mutations from the audit at
Environment
CommandsThe Windows run used a directory holding a copy of Observed: the eight that survived at
|
…sses A sort of the spans by id instead of by address passed the fixture, because the accept case listed ids that followed the addresses. Use ids that follow neither the addresses nor their reverse, and list the mutation.
KelboLive
left a comment
There was a problem hiding this comment.
Clean extension of the patch manifest loader. Deep nesting protection via RecursionError catch prevents tracebacks, shader patch support adds proper shape validation (key format, pipeline enum, revision regex, bare-name file check), and load_data() correctly gates on caller-provided bytes rather than re-reading from disk. The 28 refusal cases covering every rule plus the mutation audit provide thorough verification. Approved.
pigalot
left a comment
There was a problem hiding this comment.
I reviewed 4968e124 merged over current main 9e7eab5b. The merge is clean (tree cf564d9e) and git diff --cached --check is clean.
What I ran on Windows. After cmake --preset <dev|release>:
ctest --test-dir out/build/<preset> --no-tests=error -R '^(patch_manifest_controls|docs_links|call_evidence_check)$'3/3 pass in both presets. out\pe-env\Scripts\python.exe -B tests/patch_manifest_check.py -v runs 9 tests, OK. So the CTest registration is now exercised; the body says it wasn't.
What I traced against the runtime.
- Revisions:
PIPELINESmatches the runtime at9e7eab5b.d3d12_draw.inlusesx2w-startup-shader-29and-29cs, andmesh86_cache.inlusesx2w-startup-mesh-86-1. - Extensions: graphics reads
.txt,.vs.csoand.ps.csoand returns if either.csois missing. Compute reads.txtand.cs.cso. mesh86 reads.mesh86.txtand.ms.cso, and.ps.csoonly when the request has a pixel stage. - mesh57: leaving it out is right.
request_slot57_mesh(x2w-startup-mesh-57-3) only publishesreq_files, and nothing reads a slot-57 translation back yet.
Mutants on top of the 28 already in the thread, each run against tests/patch_manifest_check.py:
| Mutant | Result |
|---|---|
: dropped from the file check |
killed |
\ dropped from the file check |
killed |
. allowed as a name |
killed |
.. allowed as a name |
killed |
revision [1-9][0-9]* → [0-9]+ |
killed |
empty files array allowed |
killed |
mesh86 .ps.cso made required |
killed |
duplicate ext check removed |
killed |
load_data re-reads the input file |
killed |
spans.sort() → spans.sort(key=lambda s: s[2]) |
survives on Windows too (thepatrickworld's survivor; the code is from #3056) |
Blocking: file accepts names that aren't files in the manifest's directory on Windows. _file_name says the value is "for a later consumer to resolve in the manifest's directory". On this branch, parse accepts these as a shader patch's file:
NUL,CON.txtandCom1: device names. Opening<dir>\NULopens the null device, not a file in the directory.s001.txt.ands001.txt: Windows strips a trailing dot or space, so these names001.txt.a*b,a?b,a<b,a|b,a"banda<TAB>b: names Windows can't create.
The runtime that would serve these files only runs on Windows. A check run once at load time is the place to refuse them, before any consumer exists. A version I tried:
RESERVED = re.compile(r"(?i)(?:con|prn|aux|nul|com[0-9]|lpt[0-9])")
...
if (any(c in name for c in '<>:"/\\|?*') or any(ord(c) < 32 for c in name) or name in (".", "..")
or name[-1] in ". " or RESERVED.fullmatch(name.split(".")[0])):
raise ValueError(f"{where} {name!r} must be a bare Windows file name, without a directory, drive or '..'")With it, the fixture stays at 9 tests OK. All twelve names above are refused, and s001.txt, s001.cs.cso, console.txt, nulls.cso and a b.txt are still accepted. Two or three of those names next to the six existing bare-name refusals would pin it.
Non-blocking.
- The sort-key survivor: thepatrickworld's remedy (ids that don't follow the addresses in the side-by-side accept case) is still unapplied at
4968e124. - Scope: the nesting refusal is a fix to the existing loader and stands apart from the shader kind and
load_data, which both serve #3037. I'm not asking for a split; a maintainer may prefer one.
Verdict: changes requested on 4968e124, for the file name rule only.
Environment: Windows 11 25H2 build 26200.9974; Python 3.12.10; pefile from requirements-dev.txt.
This reply was AI-assisted.
|
I agree with pigalot's CHANGES_REQUESTED review — the
pigalot's suggested fix looks correct. Please add a couple of the reserved names to the fixture refusals (e.g., Non-blocking observations:
|
|
Thank you for the review, @pigalot. You're right: I pushed two commits (the first is the earlier sort-key test fix). The loader now refuses, with three separate messages and the bare-name message unchanged: any of Twelve new mutations each fail a test, and the 24 audit mutants are still killed. The sort-key mutant that survived is killed by the earlier commit; sorting by span end remains equivalent. This comment was AI-assisted. |
pigalot
left a comment
There was a problem hiding this comment.
I re-reviewed 0d733d9a on Windows. On its own it passes, but merged over current main (fdba6e15) one of its pins fails. The merge itself is clean, and git diff --cached --check reports no problems.
My earlier request is fixed. _file_name now refuses the twelve names I listed, plus CONIN$, CONOUT$, and COM or LPT followed by a superscript digit. console.txt, nulls.cso, com10.txt, conin.txt, a b.txt and .s001.txt are still accepted.
On 0d733d9a alone, out\pe-env\Scripts\python.exe -B tests/patch_manifest_check.py -v runs 9 tests, all OK, so the first Windows run of these cases passes. I also ran nine of the mutations from your table on Windows, and each fails the check:
| Mutant | Result |
|---|---|
<>"|?* check removed |
killed (9 failures) |
| control-character check removed | killed (3) |
| trailing dot/space check removed | killed (3) |
| trailing dot only | killed (2) |
| device check removed | killed (9) |
match instead of fullmatch |
killed (1 failure, 4 errors) |
| device matched against the whole name | killed (5) |
rstrip(" ") dropped |
killed (2) |
| device names case-sensitive | killed (6) |
The sort-key survivor from the earlier round is fixed too. The side-by-side ids no longer follow the addresses.
Blocking: merged with current main, test_shader_files_match_the_runtime [compute] fails.
AssertionError: Items in the first set but not the second:
'.cs.hlsl'
patch_manifest_controls fails the same way in dev and release (ctest --test-dir out/build/<preset> --no-tests=error -R '^(patch_manifest.*|docs_links|call_evidence_check|bidi_controls)$': 3 of 4 pass). This branch's base is ca659396. Since then, #3006 (7364e6a9) added this check to src/startup_stubs/d3d12_compute_dispatch.inl:
if (output == x2w::NativeComputeOutput::unmarked) {
const DWORD attributes = cache_path(path, L"", tr.key, L".cs.hlsl") ? GetFileAttributesW(path) : INVALID_FILE_ATTRIBUTES;
if (attributes == INVALID_FILE_ATTRIBUTES || (attributes & FILE_ATTRIBUTE_DIRECTORY)) { ...
return "native translation without a revision; rebuild it"; }
}So for a compute key, the runtime now looks for <key>.cs.hlsl too. It only checks that the file exists, and only when the .txt manifest carries no native compiler revision. Without that file, a patch that ships only .txt and .cs.cso with an unmarked manifest is treated as stale. The pin is doing its job here; the loader's table is behind the runtime.
A fix that matches how mesh86's .ps.cso is handled: after merging main, add .cs.hlsl to compute's extensions as an optional file. Note in the doc that the runtime needs it only for an unmarked manifest, and pin that condition the way the load_stage(L".ps.cso", ...) line is pinned. Making it required would also satisfy the set pin, but then a patch with a natively marked manifest would have to carry a file the runtime never reads.
Non-blocking: device names on current Windows. On Windows 11 build 26200, creating nul.txt, nul .txt or aux.cso in a temporary directory makes an ordinary file of that name. Only bare NUL opens the device. Older Windows versions still open these names as devices, and Microsoft's page still lists them, so refusing them is the safe rule. The doc's wording, "a name Windows would not open as a file of that name", is accurate for those versions. You might say "on some Windows versions" for the names with an extension.
Verdict: changes requested on 0d733d9a, for the .cs.hlsl pin failure after merging main only. The file-name rule is done.
Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; pefile from requirements-dev.txt.
This reply was AI-assisted.
Since R0Y00#3006 the runtime's compute loader also looks for <key>.cs.hlsl when the key's .txt has no native line, and refuses the translation without it. List it as a compute translation file, optional like mesh86's .ps.cso, since the loader does not read the .txt. Pin it beside the runtime's unmarked-manifest check.
|
CI on 0d733d9 failed in I pushed a fix: the compute manifest now accepts Because the fix needs #3006's lookup, I then merged current main into the branch (d3013cf), so the branch is green on its own; the results above are re-measured on that merge. This comment was AI-assisted. |
pigalot
left a comment
There was a problem hiding this comment.
I re-reviewed d3013cf1 on Windows. The pin failure I asked about is fixed, so I'm approving.
Fixed. compute now lists .cs.hlsl among the files the runtime reads, and leaves it out of the required ones (.txt, .cs.cso). The doc table and the new paragraph say when the runtime looks for it: only for a .txt without a native line. test_shader_files_match_the_runtime pins that condition (if (output == x2w::NativeComputeOutput::unmarked) {) the same way it pins mesh86's .ps.cso. The new accept case (s005, compute with .txt, .cs.cso and .cs.hlsl) loads, and the CLI lists its id.
Testing. I trial-merged this head over current main (c3204a9c); the merge is clean. On that tree, out\pe-env\Scripts\python.exe -B tests/patch_manifest_check.py -v runs 9 tests, all OK, including test_shader_files_match_the_runtime, which failed on 0d733d9a after merging main. bidi_controls_check.py passes. CI is green on d3013cf1.
Mutants (on Windows, each run through tests/patch_manifest_check.py):
| Mutant | Result |
|---|---|
.cs.hlsl dropped from compute's files |
killed (2 failures, 1 error) |
.cs.hlsl made required |
killed (2 failures) |
runtime condition replaced by if (true) { |
killed (2 failures) |
runtime looks for .cs.dxil instead of .cs.hlsl |
killed (3 failures) |
The first three are yours; the fourth checks that the set pin follows the extension the runtime actually reads.
The device-name note from my last review was non-blocking and still stands as a wording suggestion only.
Verdict: approve at d3013cf1.
Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; pefile from requirements-dev.txt.
This reply was AI-assisted.
Refs #3037 (follows #3056; no applier yet).
What changes
tools/patch_manifest.pykeeps its format, its strictness (lowercase hex, integerrva, parse-time span and overlap checks) and its CLI (patch manifest: <reason>, exit status 1). It gains three behaviors:tomllibrecurses once per nested array or inline table, so a manifest nested past the recursion limit raisedRecursionError, and the CLI printed a traceback. It is now refused asmanifest is nested too deeply to parse.kind = "shader": the translation files of one shader cache key, for the shader-cache translation override named in patch manifests: hash-gated memory and data patches for source-translated builds #3037. It is checked for shape only.keyis 16 lowercase hex digits andpipelineisgraphics,computeormesh86.revisionmust have the form of that pipeline's key revision:x2w-startup-shader-<n>,x2w-startup-shader-<n>csorx2w-startup-mesh-86-<n>. The loader does not check that<n>is the runtime's current number, because the runtime bumps it often; a later consumer that serves the files must compare it with the runtime (none exists yet).filesis a non-empty array of{ ext, file, sha256 }tables using the pipeline's extensions, each listed once, with the required ones present.fileis a bare file name, for a later consumer to resolve in the manifest's directory.not supported.load_data(manifest, data):loadfor a caller that has already read the input. It hashesdata, so the bytes that pass the gate are the bytes the caller then patches or translates, even if the file changes in between.loadis unchanged and shares the target comparison.docs/experiments/patch-manifests.mdgains the shader format, its pipeline table, the new cases and the mutations.Fixture
tests/patch_manifest_check.pykeeps its three tests and adds five, all on the same synthetic PE32+ (build_pe32_plus). Registration is unchanged (tests/checks/python-linux/patch_manifest.txt, CTestpatch_manifest_controls).parseand through the CLI (status 1, empty stdout, no traceback). Shape control: a 50-deep array gets pasttomlliband is refused only for its unknown key.filevalues that are not bare names.cache_path(..., L"", key, ext)and mesh86'sload_stage). mesh86's.ps.csois the only optional one.load_data: the image's bytes give the same result asload, and the flipped image is refused. After the input file is replaced by the flipped image,load_dataon the original bytes still loads andloadon the file is refused.Mutations, each run once on the final tree with the file restored by hash:
RecursionErrorno longer caughttest_deep_nesting_is_refusederrorstest_shader_patches(5 failures)test_shader_patches(2 failures)test_shader_patches(1 failure)fileremovedtest_shader_patches(6 failures)d3d12_draw.inlreads.vx.csoinstead of.vs.csotest_shader_files_match_the_runtimefails-29b)test_shader_revision_forms_match_the_runtimefails-29to-30)load_datacompares the target with itselftest_load_data_gates_the_bytes_givenfailsTested
Commit
13269fb5onmainca659396, Linux (Debian 13), Python 3.13.5, pefile 2024.8.26:Not run on Windows; the CTest registration is unchanged and was not exercised.
This PR was AI-assisted.