xtask: count \x escapes and 0x hex arrays as encoded runs in the policy check #665
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/665"
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?
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 therepository_passes_policytest) 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.rsfile both get past it:b"\x4d\x5a\x90...": every\ends the run, so the longest piece isx4d, 3 characters.[0x4d, 0x5a, 0x90, ...](xxd -istyle): every,ends the run, so the longest piece is0x4d, 4 characters.On main, a 16 KB file holding 4096 bytes as
\xNNescapes 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_runnext tolongest_encoded_runinxtask/src/policy.rs. It counts the hex digits of\xescapes and0xliterals (with_separators and type suffixes likeu8/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: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-entryu32table 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-entryCOEF0_LENS. The code marks this with ashortcut:comment.Verification
CARGO_TARGET_DIR=/home/eric/src/VIctory/target cargo test -p xtaskon main with only the two new tests added:rejects_data_smuggled_as_an_escaped_byte_stringfailed ("16413 bytes of \x-escaped hex passed"),rejects_data_smuggled_as_a_hex_byte_arrayfailed ("24607 bytes of hex array passed"), 4 passed, 2 failed.repository_passes_policyincluded.cargo run -p xtask -- policy: "asset policy: 151 files ok".cargo clippy -p xtask --tests -- -D warnings(Linux) andcargo clippy -p xtask --tests --target x86_64-pc-windows-msvc: no warnings.rustfmt --edition 2024 --check xtask/src/policy.rs: clean.No game data used.
🤖 Generated with Claude Code
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).
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.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:44:46Z.
Review: APPROVED
Tested
e950e81on Windows 11, RTX 5070, MSVC:cargo test -p xtask6 passed, including both newrejects_data_smuggled_as_*tests.cargo xtask policypasses 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.policy.rs. Nothing runs a process, opens the network or touches the environment.,,\or whitespace. A\x/0xrun therefore breaks at closing quotes, braces and comments, which keeps short tables legal and still catchesb"\x.."andxxd -idumps.[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).
Imported from Marvisak/VIctory. Originally posted by sebastianspicker on 2026-11-24T11:02:08Z.
Tested
e950e81applied ontomainffe310e(macOS, Rust 1.98.1).cargo test -p xtask: 6 passed. Without thelongest_hex_literal_runcall, the two new tests fail and the other four pass, so they test the change.cargo xtask policyonffe310ewith the PR: 154 files ok. Also with a larger pending patch on top that adds GFX10 instruction-word test arrays: 163 files ok.\x/0xrun 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.
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.
xtask/src/policy.rs(+76/-0). Addslongest_hex_literal_run()which counts hex digits across\xNNescapes and0xliterals separated only by commas/whitespace/backslashes, catching embedded data smuggled as byte-string literals orxxd -ihex arrays that the existing run detector sees as many short 3-4 char runs. Correctly skips type suffixes (u8,u32).main.cargo test -p xtask→ 6/6 passed, including the two new tests that reject a 4096-byte\xbyte string and a 4096-byte0xarray while still accepting short constant tables, plusrepository_passes_policyconfirms the whole repo still complies.No issues found.
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.