xtask: reject decimal byte arrays in the asset policy #2244
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2246"
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 xiaotu030202 on 2026-11-25T08:46:53Z.
What this does
xtask's asset policy catches copied data in text by shape: a long hex/base64run, or a long run of
\xNN/0xNNliterals. A[u8]dump written as plaindecimal literals passes both, and the source said so:
This adds the rule and drops the note.
How
longest_decimal_run(new, next tolongest_hex_literal_run) walks the fileand counts byte-range literals in one unbroken run. A literal counts when it is
0,7,255count;007does not),1u8,0.5do not count),,, spaces, tabs or newlines.checkrejects a run longer thanMAX_ENCODED_RUN, the same 512 the two hexrules use, with the message
A run of digits longer than three is skipped rather than folded: it cannot be a
byte, and folding an address or a hash overflows
u32.Why counted in literals, not digits
Digits would reject tables the tree needs:
crates/victory-formats/src/xma/tables.rsholds
COEF0_LENS(272 byte-sized entries) andCOEF0_SYMS(272 indices).cargo xtask policyover the whole tree:The worst run anywhere is 272, so 512 leaves the existing tables alone with room
to spare while still catching an actual dump (4096 bytes is 4095-4096 literals).
Tests
Two new tests in
xtask/src/policy.rs:rejects_data_smuggled_as_a_decimal_byte_array— 4096 synthetic bytes asdecimal literals, both comma-separated on one line and one entry per line.
The one-line form asserts the specific message, so a different rule firing
would not make it pass silently.
accepts_tables_of_small_decimals—COEF0_LENS-shaped (272 byte-sizedentries) and
COEF0_SYMS-shaped (272 indices) tables still pass, and so do1u8suffixes, fractions and leading zeros, which are not byte literals.Both use the existing
synthetichelper, so nothing from the game is involved.Verification
On the pinned 1.98.1, with the MSVC build tools:
Worth noting:
repository_passes_policyis what caught the overflow while I waswriting this — a smaller test set would not have. It is the reason the fold is
guarded above.
Also clean:
cargo clippy -p xtask --all-targets— no warningscargo xtask policy—182 files okrustfmt --edition 2024 --check xtask/src/policy.rsNothing here touches game data.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:48:19Z.
Review: CHANGES_REQUESTED
Real bug found in local testing:
cargo test -p xtask --lockedafter merging into main940d32f69bfails —policy::tests::repository_passes_policypanics at xtask/src/policy.rs:258 withattempt to multiply with overflow(debug build).Cause:
longest_decimal_runfolds every digit run into au32(v * 10 + digit) before thebarecheck rejects runs longer than 3 digits. Any file in the repo with a digit run of ~10+ characters (hashes, packed decimals, version strings) overflows. The other 7 policy tests pass.Fix: only compute
valuewhendigits <= 3(it is unused otherwise), e.g.let value = if digits <= 3 { fold } else { u32::MAX };— or use saturating arithmetic. Please re-push and I will re-run the suite.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T09:25:27Z.
Ran
cargo xtask policyon this branch (Windows):asset policy: 182 files ok— no false positives from the decimal-run rule.Read through
longest_decimal_run: the literal shape is right — ≤3 digits, no leading zero, separator-only adjacency, and a value cap at 0xFF so256-class entries can't extend a run. Counting literals rather than digits correctly leavesCOEF0_LENS/COEF0_SYMS(272 entries) under the 512 limit, and digit runs longer than three (123456789in hashes/addresses) bail before the fold so nothing overflows.Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T10:29:17Z.
Independent local verification (Windows, Rust 1.100.0 / MSVC, no game data, no GPU) at head
e18c766:cargo test -p xtask --locked— 8 tests passed, including the newrejects_data_smuggled_as_a_decimal_byte_arrayandaccepts_tables_of_small_decimals.cargo xtask policy—asset policy: 182 files ok, exit 0.cargo test --workspace --locked— exit 0 (all doc-tests ok).The decimal-byte-array detection does not trip the repo policy scan on this tree. I did not check false positives against game-derived numeric tables (no game files present); the synthetic negative-control style tests above are the extent of my validation. AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only Rust tooling). No assets, executables or extracted data used.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:31:48Z.
Automated triage for the maintainers.
Merge candidate (worth a look). This closes the
shortcut:noted inxtask/src/policy.rs, where decimal byte arrays passed the asset policy. It addslongest_decimal_run, which counts runs of bare byte-sized decimal literals and rejects any run over the existingMAX_ENCODED_RUN(512). It only tightens the allowlist. I checked that the largest table in the tree, incrates/victory-formats/src/xma/tables.rs, stays under the limit. Two contributors reportcargo xtask policyclean on this branch, and the branch merges cleanly.On your reply: confirmed. There are no check runs on this head yet because the workflow is waiting for maintainer approval (first-time contributor), not because it's missing. A maintainer should approve the run before merging.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by xiaotu030202 on 2026-11-25T15:38:05Z.
The triage note says "CI has not run on this head, so a maintainer should start it before merging." One detail that may save someone time:
CI did run — it is waiting for approval, not missing.
action_requiredis GitHub's first-time-contributor gate: a workflow triggered by apull_requestfrom a fork needs a maintainer to approve it once, and until then it shows as neither queued nor failed. There is a "Review deployments / Approve and run" button on the run page, or Settings → Actions → "Require approval for first-time contributors" can be relaxed.So nothing is stuck — someone with write access just has to click approve and the existing
ci.ymlwill run one18c766. I cannot approve it myself (no write access to the base repo, and the approval is deliberately not delegable).The other two local reports stand as they are:
cargo xtask policyclean at 182 files,cargo test -p xtask --locked8 passed,cargo test --workspace --lockedexit 0. Those were run on this branch by @kotekompotek and @cloph-dsp, so the merge decision does not depend on the CI result — it is a second opinion, not the only one.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:05:41Z.
Review: COMMENTED
Reviewed and verified against
main(63bcca43) on Windows 11 — clean and ready to merge:longest_decimal_run(xtask/src/policy.rs:235-275) rejects runs of more thanMAX_ENCODED_RUN(512) bare byte-range (0..=255) decimal literals while restricting to<= 3digits, no leading zeros on multi-digit numbers, and no type suffix or decimal point, avoiding false positives on legitimate small lookup tables (e.g., 272-entryCOEF0_LENS), floats, and addresses.63bcca43repository cleanly (191 files ok).Local verification:
cargo test --locked -p xtask: 8/8 passedcargo clippy --locked -p xtask --tests -- -D warnings: 0 warningscargo xtask policy(using this PR's updated policy on63bcca43):191 files okView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.