xtask: count \x escapes and 0x hex arrays as encoded runs in the policy check #665
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!665
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/665/head"
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?
@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 UTCWhat
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
@sebastianspicker on GitHub · 2026-11-24 11:02 UTC · original
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.
@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.
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.
@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.