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

Manually merged
github merged 1 commit from gh-pr/665/head into gh-pr/665/base 2026-11-26 04:12:03 +00:00
Owner

@⁠coderanonymus on GitHub · 2026-11-24 06:24 UTC · original
coderanonymus:policy-escaped-hex → main · +76 −0 · 1 files · 1 commits · merged 2026-11-25 00:09 UTC

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

**@⁠coderanonymus** on GitHub · 2026-11-24 06:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/665) `coderanonymus:policy-escaped-hex` → `main` · +76 −0 · 1 files · 1 commits · merged 2026-11-25 00:09 UTC ## 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)
The run check split on every byte that is not alphanumeric or +/=, so
b"\x4d\x5a..." broke into 3-character pieces and an xxd -i style
[0x4d, 0x5a, ...] array into 4-character pieces. Either form of up to
about 100 KB of copied bytes passed the check and the pre-commit hook.

Also count the hex digits of \x escapes and 0x literals that have only
commas, whitespace or backslashes between them, and flag the file when
that passes the same 512 limit. The largest such run in the tree is 36
digits. Decimal arrays are still not caught.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:12:03 +00:00
github manually merged commit e950e81756 into gh-pr/665/base 2026-11-26 04:12:03 +00:00
Author
Owner

@⁠sebastianspicker on GitHub · 2026-11-24 11:02 UTC · original

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.

**@⁠sebastianspicker** on GitHub · 2026-11-24 11:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/665#issuecomment-7129568599) 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.
Author
Owner

@⁠ErRusso on GitHub · 2026-11-24 11:19 UTC · original

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.

**@⁠ErRusso** on GitHub · 2026-11-24 11:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/665#issuecomment-7129946028) ## 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.
Author
Owner

@⁠molodayamama on GitHub · 2026-11-24 14:02 UTC · original

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.

**@⁠molodayamama** on GitHub · 2026-11-24 14:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/665#issuecomment-7133742231) 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.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!665
No description provided.