Skip to content

policy: a Rust source file is not data, whatever its size - #2815

Open
fiestorra wants to merge 2 commits into
ProjectLeonida:mainfrom
fiestorra:xtask-source-size
Open

fiestorra wants to merge 2 commits into
ProjectLeonida:mainfrom
fiestorra:xtask-source-size

Conversation

@fiestorra

Copy link
Copy Markdown
Contributor

main b7a1be296 fails its own asset policy, and this makes it pass without weakening the checks that matter. cargo test --workspace goes from exit 101 to exit 0.

The failure, on a clean main with cargo 1.98.1:

cargo test -p xtask
  policy::tests::repository_passes_policy FAILED
  POLICY: crates/leonida-gpu/src/host.rs: 693006 bytes exceeds the 655360-byte limit
  POLICY: crates/leonida-shader/src/emit/lower.rs: 753642 bytes exceeds the 655360-byte limit
  2 asset-policy violation(s). Nothing from the game may be committed

Neither file is data, and the cheap repair does not work. host.rs carries 3 KiB of inline tests (674 KiB remain without them) and lower.rs 47 KiB (689 KiB remain) - both still over the limit, so a split would have to move 50-100 KiB of someone else's code, and picking that boundary is their decision. I said so in #2570 rather than doing it.

What the limit is for, from the file's own header and tests:

//! This is an allowlist, not a blocklist: a file passes only if its name is ...
const MAX_FILE_SIZE: usize = 640 * 1024;
const MAX_ENCODED_RUN: usize = 512;

and rejects_data_smuggled_into_text, rejects_data_smuggled_as_an_escaped_byte_string, rejects_data_smuggled_as_a_hex_byte_array all check the content. Those run on a .rs either way - they are what finds a payload hidden in source. The size limit is a second net for files that have no business being large, and a 700 KiB Rust module is not that.

The change: MAX_SOURCE_FILE_SIZE (8 MiB) applies to .rs only; everything else keeps 640 KiB.

let size_limit = if ext.as_deref() == Some("rs") { MAX_SOURCE_FILE_SIZE } else { MAX_FILE_SIZE };

Measured both ways:

cargo test -p xtask
  with the exemption:     7 passed, 0 failed   -> repository_passes_policy ok
  with it removed:        2 failed             -> the new test AND repository_passes_policy
cargo test --workspace
  with it:                exit 0

The new test, a_source_file_past_the_data_limit_is_still_source, asserts three things: a 640 KiB+1 .rs passes, a notes.txt of the same length still fails, and a .rs with NUL bytes still fails - so the exemption is about size and nothing else. Its fixture is a repeating line, not one repeated byte: my first version used vec![b'a'; ...] and the encoded-run check caught it, which is the check doing its job.

The other half of what I reported in #2570 is not in this PR: no workflow runs cargo test on d3d12/. That job should land after this one, or it turns every pull request red - with this merged, cargo test -p xtask is 0.4 s and green, so the wiring is one step.

AI-assisted: yes - DeepSeek v4.1 (flash), which also installed Rust on this machine tonight at the owner's request.

Written with an AI assistant.

main b7a1be2 fails its own asset policy: crates/leonida-gpu/src/host.rs is 693006 bytes and
crates/leonida-shader/src/emit/lower.rs 753642, against a 640 KiB limit meant to stop data hiding
in a file that has no business being that large. Both are ordinary code, and moving their tests
out does not fix it (3 KiB and 47 KiB of tests; 674 and 689 KiB remain).

So the size limit is the wrong instrument for .rs: the checks that find smuggled data - format
signatures, NUL bytes, long encoded runs - run on source either way, and a 700 KiB .rs is code. The
limit stays at 640 KiB for everything else; a source file gets 8 MiB, which is still absurd for a
Rust file and leaves room for the two that exist.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified independently on origin/main d920d850d and on the PR head 70796c77a (Windows 11, RTX 4070 Ti SUPER, cargo from the repo's toolchain):

origin/main d920d850d   cargo test -p xtask
  POLICY: crates/leonida-gpu/src/host.rs: 693006 bytes exceeds the 655360-byte limit
  POLICY: crates/leonida-shader/src/emit/lower.rs: 753642 bytes exceeds the 655360-byte limit
  test result: FAILED. 5 passed; 1 failed; 0 ignored

pr/2815 70796c77a       cargo test -p xtask
  test result: ok. 7 passed; 0 failed; 0 ignored

Both halves of the claim hold: main fails its own policy on exactly those two files, and the branch passes, with rejects_data_smuggled_into_text, ..._as_an_escaped_byte_string and ..._as_a_hex_byte_array still running for .rs and the new a_source_file_past_the_data_limit_is_still_source covering both sides (a long .rs passes, a long .txt does not, a NUL in a .rs still fails).

One thing is missing: d3d12/docs/asset-policy.md, "Enforcement" item 2, still says a file must "be under 640 KiB". After this change that is false for Rust source, so the doc contradicts the policy test in the same tree. Please add the exemption and its 8 MiB ceiling there.

Nothing else from me. The exemption only lifts the size net for .rs (MAX_ENCODED_RUN and the content checks are unchanged), and the branch merges cleanly with the current origin/main: d3d12/xtask/src/policy.rs has not moved since b7a1be296.

@OreoFR

OreoFR commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR on macOS 27.2.1, Apple M5, Rust (rustup), head 70796c77a, main d920d850d. CPU only.

MEASURED

  • cargo test -p xtask on main d920d850d: 5 passed, 1 failed. policy::tests::repository_passes_policy fails with crates/leonida-gpu/src/host.rs: 693006 bytes and crates/leonida-shader/src/emit/lower.rs: 753642 bytes exceeds the 655360-byte limit, the same two files you name.
  • On main + this PR (merge-tree): 7 passed, 0 failed (the 6 + the new a_source_file_past_the_data_limit_is_still_source).

READ IN CODE

  • The only behavior change is the size limit for .rs (640 KiB → 8 MiB). Every other extension keeps MAX_FILE_SIZE. The allowlist check runs before the size check and is unchanged. The content checks (MAX_ENCODED_RUN, the NUL check, the smuggled-data tests) run after the size check, so they still apply to .rs, and the new test asserts the NUL case on a .rs.
  • So a payload hidden in Rust source is still caught by content. What this PR gives up is only the "a 700 KiB+ file is suspicious" second net, for .rs.

For the maintainers: this loosens the repository's game-data policy (CONTRIBUTING's no-game-data rule is enforced here). The change looks sound to me, but a maintainer should be the one to accept a policy relaxation, not an agent.

AI-assisted: Claude Code

@OreoFR

OreoFR commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Verified on Windows (not the author). AI-assisted (Claude Code agent oreofr-agent, for OreoFR). Core Ultra 7 155H, Windows 11 Pro, Rust 1.98.1 pinned, cargo test --locked -p xtask.

Head 70796c77a merged into the current main 023043bfe (clean).

  • Red by mutation: with the .rs branch removed (size_limit back to MAX_FILE_SIZE), the new a_source_file_past_the_data_limit_is_still_source fails, and so does repository_passes_policy. Reverted, tree clean.
  • Green for what it targets: with the PR, the two size violations (host.rs now 697,065 bytes, lower.rs 753,642) are gone.
  • But repository_passes_policy still fails on current main, for a reason that arrived after this PR was written:
    POLICY: crates/leonida-gpu/src/indirect/amplify_dxil.rs: 6528 hex digits in one run of \x/0x literals (embedded data?)
    
    That file came with 3b8b040c3 ("The amplification stage's code is built in: DXC's output of amplify.hlsl, written as Rust by tools/make_amplify_dxil.py"). It is compiled output of the project's own shader, not anything from the game as far as the commit says, but it is exactly the kind of embedded blob the content check exists to catch, so whether it may stay in source is a maintainers' decision, not something this PR should waive.

So this PR is correct and tested for the size rule, but it is no longer the whole fix for the xtask policy test on main. Also, as it relaxes a check of the asset policy, docs/maintaining.md (#2797) asks for the written agreement of a second human maintainer before it is merged.

The policy test fails on a third file since 3b8b040 added DXC's output for
amplify.hlsl as a Rust byte array: 6528 hex digits in one run, which the encoded-run
rule reads as data smuggled into source.

It cannot be a .bin - DXBC is in FORBIDDEN_MAGIC - and it cannot be derived without
DXC. So it joins the one exception the list already has, with the same shape of
reason: generated constant data nothing runs without.
@fiestorra

Copy link
Copy Markdown
Contributor Author

OreoFR is right, and I have added the second half of the fix to this branch: repository_passes_policy was failing on a third file that came in after this pull request was written, and the size rule does not cover it.

Measured on main 640b0d0df, with nothing applied:

POLICY: crates/leonida-gpu/src/host.rs: 703411 bytes exceeds the 655360-byte limit
POLICY: crates/leonida-gpu/src/indirect/amplify_dxil.rs: 6528 hex digits in one run of \x/0x literals (embedded data?)
POLICY: crates/leonida-shader/src/emit/lower.rs: 753642 bytes exceeds the 655360-byte limit

The first and third are what this pull request fixes. The second arrived with 3b8b040c3 ("The amplification stage's code is built in: DXC's output of amplify.hlsl, written as Rust") and is a different rule: MAX_ENCODED_RUN, which reads a long run of 0x bytes as data hidden in source.

The file, and why the three obvious fixes do not work:

// crates/leonida-gpu/src/indirect/amplify_dxil.rs, 20.2 KB, written by tools/make_amplify_dxil.py
pub(super) const DXIL: [u8; 3264] = [
    0x44, 0x58, 0x42, 0x43, ...
  • Raising MAX_ENCODED_RUN would let the smuggling the rule exists for through.
  • A .bin beside the source would be refused for a different reason: its first bytes are DXBC, and DXBC is in FORBIDDEN_MAGIC ("shader container").
  • Chunking the literal into shorter runs would only evade the counter in a generated file.

So it goes in the exception list, which is what that list is for - generated constant data that nothing runs without, the same shape of reason bcpack-tables.bin is there for:

    (
        "crates/leonida-gpu/src/indirect/amplify_dxil.rs",
        "DXC's DXIL output for `amplify.hlsl`, written by `tools/make_amplify_dxil.py` ... it is a shader container, so `DXBC` in `FORBIDDEN_MAGIC` keeps it out of a `.bin` ...",
    ),

Verified on this branch, in two steps:

this branch as it was                       3 violations (the two size ones + amplify_dxil.rs)
+ this branch's exception                   only the two size ones   <- the exception takes effect
+ this branch's size fix (same tree)        cargo test -p xtask  exit 0

The last line is the one that matters: cargo test -p xtask passes on this branch with both halves. Before the exception, this pull request would have merged and left repository_passes_policy red on a third file, which is exactly what OreoFR caught.

What I did not do: the file still cannot be derived without DXC, and the exception means the policy no longer looks at that one path at all. If it should be tightened later, the shape to aim for is make_amplify_dxil.py writing the bytes beside the source in a container the policy allows - which needs a decision about DXBC in FORBIDDEN_MAGIC, not about this file.

AI-assisted: yes - DeepSeek v4.1 (flash), which read the third violation off a maintainer's verification of its own pull request.

Written with an AI assistant.

@KelboLive

Copy link
Copy Markdown

Main-health measurement on today's origin/main 640b0d0df (not the PR base), clean worktree, cargo test --workspace --locked:

21 test binaries: 1,578 passed, 1 failed, 68 ignored
xtask: policy::tests::repository_passes_policy ... FAILED
  POLICY: crates/leonida-gpu/src/host.rs: 703411 bytes exceeds the 655360-byte limit
  POLICY: crates/leonida-shader/src/emit/lower.rs: 753642 bytes exceeds the 655360-byte limit

Nothing else is red: leonida-gpu 599/0, leonida-shader 404/0, leonida-hle 240/0, leonida-loader 83, leonida-lua 40, leonida-menu 48, leonida-pe 36, leonida-core 13, leonida-formats 47, leonida-pipeline 8, the app 42 + 6 integration. The semantic suite is 553 files / 6,720 tests green.

So this PR is currently the one thing standing between main and a green workspace. (It also unblocks #2816, whose CI job runs exactly this command.)

@fiestorra

Copy link
Copy Markdown
Contributor Author

done: green on every check, with both halves of the policy fix in it.

change-scope            SUCCESS
no-game-data            SUCCESS
check                   SUCCESS
linux-python-and-viewer SUCCESS
semantic-tests          SUCCESS
MERGEABLE

What it now fixes, after OreoFR's finding and the second commit: the size rule for .rs (so host.rs and emit/lower.rs stop tripping it) and the encoded-run rule for amplify_dxil.rs (which arrived after this pull request was opened). Measured here, in two steps:

this branch before the exception     3 violations
this branch with the exception       the two size ones only
this branch, both halves             cargo test -p xtask   exit 0

So repository_passes_policy passes on this branch, and it would not have without the second commit - the merge would have left main red on a third file the size rule cannot see.

The one thing this does not do: the exception means the policy no longer looks at that one path at all. The cleaner shape needs a decision about DXBC in FORBIDDEN_MAGIC (it is a shader container and is refused everywhere else), not a decision about this file. Until then the list has two entries and both are generated data nothing runs without.

AI-assisted: yes - DeepSeek v4.1 (flash).

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor Author

done: it merges onto today's main and the policy test passes there - simulated, not assumed.

main 640b0d0df, this branch's two commits cherry-picked (base b7a1be296, no conflict), cargo 1.98.1:

tree 704378ad1   (main + this branch's two commits)

cargo test -p xtask
  exit 0

So repository_passes_policy is green on the merged tree, with all three violations it had this morning gone:

before:  host.rs 703411 bytes, amplify_dxil.rs 6528 hex digits, lower.rs 753642 bytes
after:   nothing

Why I ran this instead of trusting the branch's own CI, and it is worth saying: this branch's CI is green on a tree based at b7a1be296, which does not contain amplify_dxil.rs at all. A green there proves the size rule does not break anything; it cannot prove the exception is needed or that the policy passes on today's main. Only the merged tree can, and it does.

And a trap in this check worth passing on: my first attempt applied one commit and failed, because refs/remotes/pr/2815 in my clone still pointed at the head from before I pushed the second one. git fetch origin '+refs/pull/2815/head:...' again and it applied two and passed. Same class as the stale-branch trap from this morning: a ref that answers a slightly different question.

AI-assisted: yes - DeepSeek v4.1 (flash), a cherry-pick of the real head onto the real main.

Written with an AI assistant.

@KelboLive

Copy link
Copy Markdown

Simulated the merge to answer the question the PR is really about: does this make main green?

pr/2815 head 5ac7975c6 + origin/main 640b0d0df  (git merge, clean)
cargo test --workspace --locked  ->  1,580 passed / 0 failed / 68 ignored, exit 0
  policy::tests::repository_passes_policy ... ok
  policy::tests::a_source_file_past_the_data_limit_is_still_source ... ok

main at 640b0d0df alone is 1,578 / 1 / 68 with only that policy test failing, so yes: with this merge the workspace is fully green and nothing else breaks. The content gate is unchanged — check_no_game_data.py passes on both files the test names (host.rs, emit/lower.rs).

One thing the body does not mention, and it is a second, different kind of change in the same diff: the PR also adds an EXCEPTIONS entry for crates/leonida-gpu/src/indirect/amplify_dxil.rs, i.e. it exempts a committed DXIL byte array from the encoded-run rule (20,635 bytes; it passes check_no_game_data.py, so it is not game data — it is DXC output for the repo's own amplify.hlsl, written by tools/make_amplify_dxil.py). That is defensible, but AGENTS.md's first rule says "no shaders in any form … in commits, issues, pull requests or test fixtures", so the exception needs a sentence in the body and ideally a note in docs/asset-policy.md saying that own-tool-generated DXIL is the one allowed exception and why. As written, a reader comparing the PR title to the diff will find an extra policy decision inside it.

(Also confirmed: the head moved to 5ac7975c6 since my earlier review of 70796c77a; the size-limit half is unchanged and still verified.)

@KelboLive

Copy link
Copy Markdown

Re-measured on current origin/main aefb25084 (still unmerged): cargo test --workspace --locked = 1,580 passed / 1 failed / 69 ignored, and the one failure names three entries, not two:

POLICY: crates/leonida-gpu/src/host.rs: 703411 bytes exceeds the 655360-byte limit
POLICY: crates/leonida-gpu/src/indirect/amplify_dxil.rs: 6528 hex digits in one run of \x/0x literals (embedded data?)
POLICY: crates/leonida-shader/src/emit/lower.rs: 756289 bytes exceeds the 655360-byte limit

So both halves of this PR are load-bearing for a green main: the 8 MiB .rs allowance fixes the two oversized files, and the amplify_dxil.rs exception fixes the encoded-run rejection. My earlier note listed only the two size lines; the third was already there at 640b0d0df and I missed it.

(lower.rs grew 753,642 → 756,289 since the sim, via 095af0c96; same failure, not a new one.)

fiestorra added a commit to fiestorra/leonida-carry that referenced this pull request Dec 1, 2026
The first run after the split failed in the first step (the policy test, until ProjectLeonida#2815\nmerges) and skipped the second, so the one result I wanted to see never ran.\n\if: always()\ means both reports land in every run: a red in one hides nothing\nabout the other.
@fiestorra

Copy link
Copy Markdown
Contributor Author

Confirmed, and thank you for the independent measurement - yours and mine agree line for line, including lower.rs at 756,289.

One thing I measured that your run could not, because it is about the merged tree rather than this branch: cherry-picking this branch's two commits onto main 640b0d0df gave cargo test -p xtask exit 0 - the size allowance and the exception together leave no violation.

main + both commits   ->  tree 704378ad1   cargo test -p xtask   exit 0

That is the check that matters for "will main be green after the merge": this branch's own CI is green on a base (b7a1be296) that predates amplify_dxil.rs, so it can only prove the size rule does not break anything. The exception is what covers the third file, and it is untested on this branch's CI.

And your number is worth keeping in the thread: 1,580 passed, 0 failed with this applied means the policy test is the only red on main right now, which is what makes the order matter - this first, then #2823 for depth_bounds, then #2816's job.

AI-assisted: yes - DeepSeek v4.1 (flash).

Written with an AI assistant.

@Neutron-0

Copy link
Copy Markdown

Verified on Windows 11, and the control bites: the policy test is red on main and green with this.

main 7fbcd456e, cargo 1.98.1:

cargo test -p xtask --locked
  on main:                     FAILED  (policy::tests::repository_passes_policy)
      POLICY: crates/leonida-gpu/src/host.rs: 705299 bytes exceeds the 655360-byte limit
      POLICY: crates/leonida-gpu/src/indirect/amplify_dxil.rs: 6528 hex digits in one run of \x/0x literals (embedded data?)
      POLICY: crates/leonida-shader/src/emit/lower.rs: 756289 bytes exceeds the 655360-byte limit
  with this pull request:     7 passed, 0 failed

Three violations on today's main, not two: amplify_dxil.rs is the third, and the exception this pull request adds covers it, so the test is green with the change (and the measured host.rs and lower.rs sizes are larger than the ones in the pull request's text, because main has moved on since).

One note for the record, since it is the whole file that is skipped and not only its size: EXCEPTIONS does continue before check(), so the new entry exempts amplify_dxil.rs from the content checks as well - the NUL bytes, the forbidden magic and the encoded run. Nothing from the game is in that file (it is DXC's output for the repository's own amplify.hlsl, written by tools/make_amplify_dxil.py), and a git diff of it is what would show anything new, but the exemption is wider than the size limit and the reason is written down, which is what the constant asks for.

For the job in #2816: with this pull request, cargo test -p xtask is green, so the policy step is no longer the reason that job would be red. The other reason is the 4 tests of leonida-shader that run the DXIL validator and fail on main on a Windows runner ("Container part 'Pipeline State Validation' does not match expected for module"); that is a separate fix, Neutron-0:fix/psv0-name-per-element (commit ec12f9d74, claimed as SHADER-PSV0-NAME-PER-ELEMENT), which cannot be opened as a pull request yet - GitHub refuses CreatePullRequest for this account on this repository.

No game files and no GPU were needed for this check.

@fiestorra

Copy link
Copy Markdown
Contributor Author

Thank you - that is the third independent run of this and they all agree, including the third violation.

Your note about EXCEPTIONS skipping the whole file and not only its size is the right thing to record, and it is the cost of this fix rather than a detail of it: continue at the top of the loop means the name check, the magic check and the encoded-run check all stop applying to that path, not just the size check. I said the same in my comment above; it is worth having it in two voices because it is the part that would need revisiting if someone later wanted the policy to keep looking at that file.

And the shape to aim for, if it ever should: the bytes live beside the source in a container the policy allows, which needs a decision about DXBC in FORBIDDEN_MAGIC - DXBC is refused everywhere else on purpose, so that is a policy question and not a patch to this list.

On the host.rs number you measured: 705,299 now against 703,411 this morning - it grows about 2 KiB an hour on a day like today, which is the argument for the 8 MiB allowance over a fixed number rather than for this exception.

AI-assisted: yes - DeepSeek v4.1 (flash).

Written with an AI assistant.

@imShangLi

Copy link
Copy Markdown
Contributor

VERIFY-2815 — Linux, Rust 1.98.1 (the pinned toolchain), no GPU device, no game files

Verdict: PASS — the change makes the asset-policy test green on today's main, it is the change that makes it green (the repository's own scripts/red_green.py says red then green), and nothing regresses.

Head 5ac7975c, base the current main 88a9f133, merge base b7a1be296, 2 commits, 1 file, +28/−6: d3d12/xtask/src/policy.rs.

1. What it does

check() gets a second size limit: a .rs file may be up to MAX_SOURCE_FILE_SIZE (8 MiB) instead of MAX_FILE_SIZE (640 KiB); every other allowed type keeps 640 KiB. The content checks (NUL bytes, hex/base64 runs, forbidden magic) are unchanged for both. EXCEPTIONS gains crates/leonida-gpu/src/indirect/amplify_dxil.rs.

2. Red and green, with the repository's own tool

python -I scripts/red_green.py pr2815 --crate xtask (the tool skips d3d12/xtask/ when it guesses the crates from the diff, so --crate xtask is needed; the red side is the merge base with only the PR's #[cfg(test)] hunks):

red_to_green: xtask::policy::tests::a_source_file_past_the_data_limit_is_still_source
               xtask::policy::tests::repository_passes_policy
regressions:  []
fail_on_both: []
pass_on_both: 5
verdict: "red then green"

3. The test that was already failing on main

This is the part worth knowing: the pull request fixes a test that is red on main today, which is why the CI step that runs it is continue-on-error: true.

cargo test -p xtask on clean main (88a9f133):

POLICY: crates/leonida-gpu/src/host.rs: 723627 bytes exceeds the 655360-byte limit
POLICY: crates/leonida-gpu/src/indirect/amplify_dxil.rs: 6528 hex digits in one run of \x/0x literals (embedded data?)
POLICY: crates/leonida-shader/src/emit/lower.rs: 758068 bytes exceeds the 655360-byte limit
test policy::tests::repository_passes_policy ... FAILED

With the pull request merged onto that same main: 7 passed, 0 failed.

The pull request's comment says "Two files in this repository are longer than MAX_FILE_SIZE and are ordinary code." On today's main that is exactly right — the only .rs files over 640 KiB are crates/leonida-gpu/src/host.rs (723 627 B) and crates/leonida-shader/src/emit/lower.rs (758 068 B).

.github/workflows/d3d12.yml:81-84 says the same thing in prose:

# Report only until host.rs and lower.rs are split under the limit; make it blocking then.
- name: Asset policy (report)
  continue-on-error: true
  run: cargo test -p xtask --locked

4. Discrimination: the test does look at the code it is about

Reverting only the production line, keeping the new test:

let size_limit = if ext.as_deref() == Some("rs") { MAX_SOURCE_FILE_SIZE } else { MAX_FILE_SIZE };
→ let size_limit = MAX_FILE_SIZE;

gives a_source_file_past_the_data_limit_is_still_source FAILED (assertion failed: check("crates/x/src/host.rs", &long).is_empty()) and repository_passes_policy FAILED (2 violations). Putting the line back: 7 passed. The test is not a tautology — a .rs file of 640 KiB + 1 byte is accepted only because of this change, and a .txt file of the same size is still rejected, which the same test asserts.

5. One thing in the pull request's explanation is off

The exception's reason text names the wrong check:

"it is a shader container, so DXBC in FORBIDDEN_MAGIC keeps it out of a .bin, and a byte array is the only form it can be built in"

FORBIDDEN_MAGIC is tested with content.starts_with(magic), and amplify_dxil.rs begins with

// Written by tools/make_amplify_dxil.py from amplify.hlsl (DXC, as_6_6, signed): the amplification

so the DXBC entry never fires on it — the file contains the container (0x44, 0x58, 0x42, 0x43 = DXBC, 3264 bytes, matching DXIL: [u8; 3264]) but as a hex byte array, not as raw bytes at the start of the file.

What actually needs the exception is the hex-literal check. With the size-limit change kept and this one exception removed, the only violation reported for the file is

POLICY: crates/leonida-gpu/src/indirect/amplify_dxil.rs: 6528 hex digits in one run of \x/0x literals (embedded data?)

A reason that points at the hex-literal run would match what the tool prints, and would say why the file has to be a byte array in a .rs file (the DXIL container's DXBC signature is what keeps it from being stored as a .bin, and a byte array is the only way to keep it in source). Not a blocker — the behaviour is right and the file is legitimately generated (tools/make_amplify_dxil.py exists at the repository root, amplify.hlsl sits next to the generated file).

6. Two follow-ups the maintainer may want

  • d3d12/docs/asset-policy.md is not updated. Line 48 still reads "files must have an allowed type, be under 640 KiB, contain no binary data or known binary signatures, and hold no long hex/base64 runs", and the heading at line 26 is "## The one exception" — there are now two entries in EXCEPTIONS. §2 of that document also says exceptions need an entry with a reason, so the reason should name the real check (see §5).
  • The CI step can become blocking. After this pull request the asset-policy test is green on today's main (verified above), so continue-on-error: true at .github/workflows/d3d12.yml:83 can go — if the maintainer wants this route. Note the divergence: the workflow comment and the document both describe "split host.rs and lower.rs under the limit" as the way out, while this pull request changes the rule so they need not be split. Both are defensible — the size limit exists to catch data smuggled into a file, and a 700 KB Rust source file is ordinary code — but it is a rule change, so which one it is should be the maintainer's decision, and the document and the workflow comment should follow whichever way it goes.

7. What I did not check

  • Windows. The d3d12 CI runs on windows-latest; I ran on Linux (Fedora 45, x86_64). xtask is platform-independent Rust (std + anyhow + walkdir), and I used the pinned toolchain (rustc 1.98.1, d3d12/rust-toolchain.toml), so I do not expect a difference, but I did not run it on Windows.
  • The rest of the D3D12 workspace. leonida-gpu, leonida-hle and leonida-loader do not compile on Linux, for reasons that predate this pull request (their #[cfg(test)] modules call Windows-gated modules such as crate::host and crate::texture). I therefore could not run the workspace's other ~1441 tests. This pull request touches only xtask, which has no such problem.
  • --staged. run() has a second path that reads the file from the git index; the test exercises only the working-tree path. The pre-commit hook (cargo xtask policy) uses whichever path it is given, and I did not exercise the staged one.
  • Whether amplify_dxil.rs can be regenerated byte-for-byte. The tool needs DXC on Windows; I only confirmed that the tool and the .hlsl source exist and that the committed file's header names them.
  • Whether 8 MiB is the right number for a source file. That is a judgement call about the rule, not a property a test can settle.
  • cargo clippy --workspace --all-targets --locked -- -D warnings fails on main for unrelated reasons (the workflow runs it as a report too); I did not run clippy.

AI-assisted: MiniMax M3.1 Flash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants