xtask: count \x escapes and 0x hex arrays as encoded runs in the policy check #665

Merged
coderanonymus merged 1 commit from upstream-pr/665 into main 2026-11-25 00:09:15 +00:00
coderanonymus commented 2026-11-24 06:24:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by coderanonymus on 2026-11-24T06:24:46Z.


What

The asset-policy check (cargo xtask policy, the pre-commit hook and the repository_passes_policy test) looks for long hex/base64 runs. It splits the file on every byte that is not alphanumeric or +/=. The two usual ways to paste bytes into a .rs file both get past it:

  • b"\x4d\x5a\x90...": every \ ends the run, so the longest piece is x4d, 3 characters.
  • [0x4d, 0x5a, 0x90, ...] (xxd -i style): every , ends the run, so the longest piece is 0x4d, 4 characters.

On main, a 16 KB file holding 4096 bytes as \xNN escapes and a 24 KB file holding them as a hex array both pass. Up to about 100 KB of copied bytes fits under the 512 KiB file limit this way.

This PR adds longest_hex_literal_run next to longest_encoded_run in xtask/src/policy.rs. It counts the hex digits of \x escapes and 0x literals (with _ separators and type suffixes like u8/u32) that have only commas, whitespace or backslashes between them. Backslashes cover Rust's \-newline string continuation. A file fails when that count passes the existing 512 limit:

src/data.rs: 8192 hex digits in one run of \x/0x literals (embedded data?)

The largest such run in the current tree is 36 digits (crates/victory-shader/src/emit/lower.rs). Short constant tables stay legal. A test checks that a 16-entry u32 table passes.

Known limit: decimal arrays like [77, 90, ...] still pass. They are not hex, and the tree has real decimal format tables, such as xma's 272-entry COEF0_LENS. The code marks this with a shortcut: comment.

Verification

  • CARGO_TARGET_DIR=/home/eric/src/VIctory/target cargo test -p xtask on main with only the two new tests added: rejects_data_smuggled_as_an_escaped_byte_string failed ("16413 bytes of \x-escaped hex passed"), rejects_data_smuggled_as_a_hex_byte_array failed ("24607 bytes of hex array passed"), 4 passed, 2 failed.
  • The same command with the fix: 6 passed, 0 failed, repository_passes_policy included.
  • cargo run -p xtask -- policy: "asset policy: 151 files ok".
  • A temporary probe (not committed) ran the new measure over every tracked file. The top value was 36 digits.
  • cargo clippy -p xtask --tests -- -D warnings (Linux) and cargo clippy -p xtask --tests --target x86_64-pc-windows-msvc: no warnings.
  • rustfmt --edition 2024 --check xtask/src/policy.rs: clean.
  • xtask is a host tool, so no Windows-only tests apply. No game was run.

No game data used.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6575998359 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/665). Originally posted by [coderanonymus](https://github.com/coderanonymus) on 2026-11-24T06:24:46Z. --- ## What The asset-policy check (`cargo xtask policy`, the pre-commit hook and the `repository_passes_policy` test) looks for long hex/base64 runs. It splits the file on every byte that is not alphanumeric or `+/=`. The two usual ways to paste bytes into a `.rs` file both get past it: - `b"\x4d\x5a\x90..."`: every `\` ends the run, so the longest piece is `x4d`, 3 characters. - `[0x4d, 0x5a, 0x90, ...]` (`xxd -i` style): every `, ` ends the run, so the longest piece is `0x4d`, 4 characters. On main, a 16 KB file holding 4096 bytes as `\xNN` escapes and a 24 KB file holding them as a hex array both pass. Up to about 100 KB of copied bytes fits under the 512 KiB file limit this way. This PR adds `longest_hex_literal_run` next to `longest_encoded_run` in `xtask/src/policy.rs`. It counts the hex digits of `\x` escapes and `0x` literals (with `_` separators and type suffixes like `u8`/`u32`) that have only commas, whitespace or backslashes between them. Backslashes cover Rust's `\`-newline string continuation. A file fails when that count passes the existing 512 limit: ``` src/data.rs: 8192 hex digits in one run of \x/0x literals (embedded data?) ``` The largest such run in the current tree is 36 digits (`crates/victory-shader/src/emit/lower.rs`). Short constant tables stay legal. A test checks that a 16-entry `u32` table passes. Known limit: decimal arrays like `[77, 90, ...]` still pass. They are not hex, and the tree has real decimal format tables, such as xma's 272-entry `COEF0_LENS`. The code marks this with a `shortcut:` comment. ## Verification - `CARGO_TARGET_DIR=/home/eric/src/VIctory/target cargo test -p xtask` on main with only the two new tests added: `rejects_data_smuggled_as_an_escaped_byte_string` failed ("16413 bytes of \x-escaped hex passed"), `rejects_data_smuggled_as_a_hex_byte_array` failed ("24607 bytes of hex array passed"), 4 passed, 2 failed. - The same command with the fix: 6 passed, 0 failed, `repository_passes_policy` included. - `cargo run -p xtask -- policy`: "asset policy: 151 files ok". - A temporary probe (not committed) ran the new measure over every tracked file. The top value was 36 digits. - `cargo clippy -p xtask --tests -- -D warnings` (Linux) and `cargo clippy -p xtask --tests --target x86_64-pc-windows-msvc`: no warnings. - `rustfmt --edition 2024 --check xtask/src/policy.rs`: clean. - xtask is a host tool, so no Windows-only tests apply. No game was run. No game data used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LAKSHYA-cmd-tech commented 2026-11-24 06:54:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T06:30:02Z.

Review: APPROVED


LGTM! Tested on Windows 11 with MSVC Rust 1.98.1. cargo test -p xtask passed cleanly (6 passed), including both tests rejecting smuggled escaped byte strings and hex arrays. cargo xtask policy verified the entire tree (151 files ok).

<!-- greyfinch-sync:Marvisak/VIctory:review:6034684357 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/665#pullrequestreview-6034684357). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T06:30:02Z. **Review:** APPROVED --- LGTM! Tested on Windows 11 with MSVC Rust 1.98.1. cargo test -p xtask passed cleanly (6 passed), including both tests rejecting smuggled escaped byte strings and hex arrays. cargo xtask policy verified the entire tree (151 files ok).
catminou4 commented 2026-11-24 06:54:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T06:42:16Z.

Review: APPROVED


Verified locally on macOS 26 arm64, rustc 1.98.1 (aarch64-apple-darwin, rust-toolchain.toml) at head e950e817:

  • cargo test -p xtask --locked: 6 passed, 0 failed (includes the new encoded-run counting tests)

Approving.

<!-- greyfinch-sync:Marvisak/VIctory:review:6034789489 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/665#pullrequestreview-6034789489). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T06:42:16Z. **Review:** APPROVED --- Verified locally on macOS 26 arm64, rustc 1.98.1 (aarch64-apple-darwin, rust-toolchain.toml) at head e950e817: - `cargo test -p xtask --locked`: **6 passed, 0 failed** (includes the new encoded-run counting tests) Approving.
mercuryVM commented 2026-11-24 11:03:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:44:46Z.

Review: APPROVED


Tested e950e81 on Windows 11, RTX 5070, MSVC: cargo test -p xtask 6 passed, including both new rejects_data_smuggled_as_* tests. cargo xtask policy passes on this head (151 files). It also passes on mercuryVM/VIctory main with this merged (161 files), which already includes the LUT-heavy #703 BCPack rewrite, so the new rule doesn't flag the tree's existing constant tables.

  • Safety check (xtask): the change is pure byte scanning in policy.rs. Nothing runs a process, opens the network or touches the environment.
  • The run resets on anything other than ,, \ or whitespace. A \x/0x run therefore breaks at closing quotes, braces and comments, which keeps short tables legal and still catches b"\x.." and xxd -i dumps.
  • Edge case: the [b'0', b'x', ..] arm also matches inside identifiers or numbers (e.g. v0x1, 10x), which only adds digits to a run and can't hide data. Decimal arrays still pass, as the comment says.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6037788542 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/665#pullrequestreview-6037788542). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T10:44:46Z. **Review:** APPROVED --- Tested e950e81 on Windows 11, RTX 5070, MSVC: `cargo test -p xtask` 6 passed, including both new `rejects_data_smuggled_as_*` tests. `cargo xtask policy` passes on this head (151 files). It also passes on mercuryVM/VIctory main with this merged (161 files), which already includes the LUT-heavy #703 BCPack rewrite, so the new rule doesn't flag the tree's existing constant tables. - Safety check (xtask): the change is pure byte scanning in `policy.rs`. Nothing runs a process, opens the network or touches the environment. - The run resets on anything other than `,`, `\` or whitespace. A `\x`/`0x` run therefore breaks at closing quotes, braces and comments, which keeps short tables legal and still catches `b"\x.."` and `xxd -i` dumps. - Edge case: the `[b'0', b'x', ..]` arm also matches inside identifiers or numbers (e.g. `v0x1`, `10x`), which only adds digits to a run and can't hide data. Decimal arrays still pass, as the comment says. AI-assisted (Claude Code).
sebastianspicker commented 2026-11-24 11:04:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sebastianspicker on 2026-11-24T11:02:08Z.


Tested e950e81 applied onto main ffe310e (macOS, Rust 1.98.1).

  • cargo test -p xtask: 6 passed. Without the longest_hex_literal_run call, the two new tests fail and the other four pass, so they test the change.
  • cargo xtask policy on ffe310e with the PR: 154 files ok. Also with a larger pending patch on top that adds GFX10 instruction-word test arrays: 163 files ok.
  • Headroom: the longest \x/0x run anywhere in the tree is 104 hex digits (crates/victory-shader/src/emit/valu_tests.rs). Comments between instruction words reset the run, so test programs stay far below the 512 limit.

The decimal-array gap is marked in the code, which seems the right call for now.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129568599 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/665#issuecomment-7129568599). Originally posted by [sebastianspicker](https://github.com/sebastianspicker) on 2026-11-24T11:02:08Z. --- Tested `e950e81` applied onto `main` `ffe310e` (macOS, Rust 1.98.1). - `cargo test -p xtask`: 6 passed. Without the `longest_hex_literal_run` call, the two new tests fail and the other four pass, so they test the change. - `cargo xtask policy` on `ffe310e` with the PR: 154 files ok. Also with a larger pending patch on top that adds GFX10 instruction-word test arrays: 163 files ok. - Headroom: the longest `\x`/`0x` run anywhere in the tree is 104 hex digits (`crates/victory-shader/src/emit/valu_tests.rs`). Comments between instruction words reset the run, so test programs stay far below the 512 limit. The decimal-array gap is marked in the code, which seems the right call for now. AI-assisted.
ErRusso commented 2026-11-24 12:04:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ErRusso on 2026-11-24T11:19:18Z.


Audit: ✅ Looks good — verified & tested

Reviewed this PR as part of an audit of mergeable PRs.

  • Scope: xtask/src/policy.rs (+76/-0). Adds longest_hex_literal_run() which counts hex digits across \xNN escapes and 0x literals separated only by commas/whitespace/backslashes, catching embedded data smuggled as byte-string literals or xxd -i hex arrays that the existing run detector sees as many short 3-4 char runs. Correctly skips type suffixes (u8, u32).
  • Merges cleanly into main.
  • Tests: cargo test -p xtask → 6/6 passed, including the two new tests that reject a 4096-byte \x byte string and a 4096-byte 0x array while still accepting short constant tables, plus repository_passes_policy confirms the whole repo still complies.

No issues found.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129946028 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/665#issuecomment-7129946028). Originally posted by [ErRusso](https://github.com/ErRusso) on 2026-11-24T11:19:18Z. --- ## Audit: ✅ Looks good — verified & tested Reviewed this PR as part of an audit of mergeable PRs. - **Scope:** `xtask/src/policy.rs` (+76/-0). Adds `longest_hex_literal_run()` which counts hex digits across `\xNN` escapes and `0x` literals separated only by commas/whitespace/backslashes, catching embedded data smuggled as byte-string literals or `xxd -i` hex arrays that the existing run detector sees as many short 3-4 char runs. Correctly skips type suffixes (`u8`, `u32`). - **Merges cleanly** into `main`. - **Tests:** `cargo test -p xtask` → **6/6 passed**, including the two new tests that reject a 4096-byte `\x` byte string and a 4096-byte `0x` array while still accepting short constant tables, plus `repository_passes_policy` confirms the whole repo still complies. No issues found.
molodayamama commented 2026-11-24 14:04:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by molodayamama on 2026-11-24T14:02:33Z.


Independent Windows check of e950e81756340b10c3ef87d9c1789ae482f1a262 (Windows 10 22H2 19045, Rust 1.98.1, MSVC x64).

  • cargo test -p xtask --locked rejects_data_smuggled_as -- --test-threads=1 --nocapture: 2 passed.

The policy's regression fixtures check that long embedded runs are detected in both an escaped byte string and a hexadecimal array. No real binary content was used.

Only source-built synthetic fixtures were used. AI-assisted verification.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133742231 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/665#issuecomment-7133742231). Originally posted by [molodayamama](https://github.com/molodayamama) on 2026-11-24T14:02:33Z. --- Independent Windows check of `e950e81756340b10c3ef87d9c1789ae482f1a262` (Windows 10 22H2 19045, Rust 1.98.1, MSVC x64). - `cargo test -p xtask --locked rejects_data_smuggled_as -- --test-threads=1 --nocapture`: 2 passed. The policy's regression fixtures check that long embedded runs are detected in both an escaped byte string and a hexadecimal array. No real binary content was used. Only source-built synthetic fixtures were used. AI-assisted verification.
upstream-sync closed this pull request 2026-11-25 01:04:42 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!665
No description provided.