xtask: reject decimal byte arrays in the asset policy #2244

Open
xiaotu030202 wants to merge 1 commit from upstream-pr/2246 into main
xiaotu030202 commented 2026-11-25 08:46:53 +00:00 (Migrated from github.com)

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/base64
run, or a long run of \xNN / 0xNN literals. A [u8] dump written as plain
decimal literals passes both, and the source said so:

/// shortcut: decimal arrays (`[77, 90, ...]`) still pass, add a literal count if one shows up.

This adds the rule and drops the note.

How

longest_decimal_run (new, next to longest_hex_literal_run) walks the file
and counts byte-range literals in one unbroken run. A literal counts when it is

  • at most three digits,
  • not written with a leading zero (0, 7, 255 count; 007 does not),
  • not followed by a type suffix or a fraction (1u8, 0.5 do not count),
  • separated from the next one by nothing but ,, spaces, tabs or newlines.

check rejects a run longer than MAX_ENCODED_RUN, the same 512 the two hex
rules use, with the message

{n} byte-range decimal literals in one run (embedded data?)

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.rs
holds COEF0_LENS (272 byte-sized entries) and COEF0_SYMS (272 indices).

cargo xtask policy over the whole tree:

asset policy: 182 files ok

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 as
    decimal 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-sized
    entries) and COEF0_SYMS-shaped (272 indices) tables still pass, and so do
    1u8 suffixes, fractions and leading zeros, which are not byte literals.

Both use the existing synthetic helper, so nothing from the game is involved.

Verification

On the pinned 1.98.1, with the MSVC build tools:

$ cargo test -p xtask
running 8 tests
test policy::tests::accepts_source ... ok
test policy::tests::rejects_data_smuggled_into_text ... ok
test policy::tests::accepts_tables_of_small_decimals ... ok
test policy::tests::rejects_data_smuggled_as_an_escaped_byte_string ... ok
test policy::tests::rejects_data_smuggled_as_a_hex_byte_array ... ok
test policy::tests::rejects_game_like_files ... ok
test policy::tests::rejects_data_smuggled_as_a_decimal_byte_array ... ok
test policy::tests::repository_passes_policy ... ok
test result: ok. 8 passed; 0 failed

Worth noting: repository_passes_policy is what caught the overflow while I was
writing 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 warnings
  • cargo xtask policy — 182 files ok
  • rustfmt --edition 2024 --check xtask/src/policy.rs

Nothing here touches game data.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6600643834 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2246). Originally posted by [xiaotu030202](https://github.com/xiaotu030202) on 2026-11-25T08:46:53Z. --- ## What this does `xtask`'s asset policy catches copied data in text by shape: a long hex/base64 run, or a long run of `\xNN` / `0xNN` literals. A `[u8]` dump written as plain decimal literals passes both, and the source said so: ```rust /// shortcut: decimal arrays (`[77, 90, ...]`) still pass, add a literal count if one shows up. ``` This adds the rule and drops the note. ## How `longest_decimal_run` (new, next to `longest_hex_literal_run`) walks the file and counts byte-range literals in one unbroken run. A literal counts when it is - at most three digits, - not written with a leading zero (`0`, `7`, `255` count; `007` does not), - not followed by a type suffix or a fraction (`1u8`, `0.5` do not count), - separated from the next one by nothing but `,`, spaces, tabs or newlines. `check` rejects a run longer than `MAX_ENCODED_RUN`, the same 512 the two hex rules use, with the message ``` {n} byte-range decimal literals in one run (embedded data?) ``` 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.rs` holds `COEF0_LENS` (272 byte-sized entries) and `COEF0_SYMS` (272 indices). `cargo xtask policy` over the whole tree: ``` asset policy: 182 files ok ``` 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 as decimal 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-sized entries) and `COEF0_SYMS`-shaped (272 indices) tables still pass, and so do `1u8` suffixes, fractions and leading zeros, which are not byte literals. Both use the existing `synthetic` helper, so nothing from the game is involved. ## Verification On the pinned 1.98.1, with the MSVC build tools: ``` $ cargo test -p xtask running 8 tests test policy::tests::accepts_source ... ok test policy::tests::rejects_data_smuggled_into_text ... ok test policy::tests::accepts_tables_of_small_decimals ... ok test policy::tests::rejects_data_smuggled_as_an_escaped_byte_string ... ok test policy::tests::rejects_data_smuggled_as_a_hex_byte_array ... ok test policy::tests::rejects_game_like_files ... ok test policy::tests::rejects_data_smuggled_as_a_decimal_byte_array ... ok test policy::tests::repository_passes_policy ... ok test result: ok. 8 passed; 0 failed ``` Worth noting: `repository_passes_policy` is what caught the overflow while I was writing 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 warnings - `cargo xtask policy` — `182 files ok` - `rustfmt --edition 2024 --check xtask/src/policy.rs` Nothing here touches game data.
catminou4 commented 2026-11-25 09:06:02 +00:00 (Migrated from github.com)

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 --locked after merging into main 940d32f69b fails — policy::tests::repository_passes_policy panics at xtask/src/policy.rs:258 with attempt to multiply with overflow (debug build).

Cause: longest_decimal_run folds every digit run into a u32 (v * 10 + digit) before the bare check 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 value when digits <= 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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054378294 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2246#pullrequestreview-6054378294). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:48:19Z. **Review:** CHANGES_REQUESTED --- Real bug found in local testing: `cargo test -p xtask --locked` after merging into main 940d32f69b fails — `policy::tests::repository_passes_policy` panics at xtask/src/policy.rs:258 with `attempt to multiply with overflow` (debug build). Cause: `longest_decimal_run` folds every digit run into a `u32` (`v * 10 + digit`) before the `bare` check 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 `value` when `digits <= 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.
kotekompotek commented 2026-11-25 10:07:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T09:25:27Z.


Ran cargo xtask policy on 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 so 256-class entries can't extend a run. Counting literals rather than digits correctly leaves COEF0_LENS/COEF0_SYMS (272 entries) under the 512 limit, and digit runs longer than three (123456789 in hashes/addresses) bail before the fold so nothing overflows.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158310303 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2246#issuecomment-7158310303). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T09:25:27Z. --- Ran `cargo xtask policy` on 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 so `256`-class entries can't extend a run. Counting literals rather than digits correctly leaves `COEF0_LENS`/`COEF0_SYMS` (272 entries) under the 512 limit, and digit runs longer than three (`123456789` in hashes/addresses) bail before the fold so nothing overflows.
cloph-dsp commented 2026-11-25 11:05:22 +00:00 (Migrated from github.com)

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 new rejects_data_smuggled_as_a_decimal_byte_array and accepts_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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159761914 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2246#issuecomment-7159761914). Originally posted by [cloph-dsp](https://github.com/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 new `rejects_data_smuggled_as_a_decimal_byte_array` and `accepts_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.
Marvisak commented 2026-11-25 14:07:23 +00:00 (Migrated from github.com)

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 in xtask/src/policy.rs, where decimal byte arrays passed the asset policy. It adds longest_decimal_run, which counts runs of bare byte-sized decimal literals and rejects any run over the existing MAX_ENCODED_RUN (512). It only tightens the allowlist. I checked that the largest table in the tree, in crates/victory-formats/src/xma/tables.rs, stays under the limit. Two contributors report cargo xtask policy clean 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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163908813 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2246#issuecomment-7163908813). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:31:48Z. --- <!-- victory-triage v1 head=e18c7660278e052168006d51c6363c3add48ea09 verdict=merge-candidate at=2026-11-25T16:45:09Z --> Automated triage for the maintainers. **Merge candidate (worth a look).** This closes the `shortcut:` noted in `xtask/src/policy.rs`, where decimal byte arrays passed the asset policy. It adds `longest_decimal_run`, which counts runs of bare byte-sized decimal literals and rejects any run over the existing `MAX_ENCODED_RUN` (512). It only tightens the allowlist. I checked that the largest table in the tree, in `crates/victory-formats/src/xma/tables.rs`, stays under the limit. Two contributors report `cargo xtask policy` clean 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](https://claude.ai/code)_
xiaotu030202 commented 2026-11-25 16:09:16 +00:00 (Migrated from github.com)

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.

GET /repos/Marvisak/VIctory/actions/runs?head_sha=e18c766…
  pull_request  completed/action_required  2026-11-25T08:56:28Z

action_required is GitHub's first-time-contributor gate: a workflow triggered by a pull_request from 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.yml will run on e18c766. 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 policy clean at 182 files, cargo test -p xtask --locked 8 passed, cargo test --workspace --locked exit 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167145003 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2246#issuecomment-7167145003). Originally posted by [xiaotu030202](https://github.com/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.** ``` GET /repos/Marvisak/VIctory/actions/runs?head_sha=e18c766… pull_request completed/action_required 2026-11-25T08:56:28Z ``` `action_required` is GitHub's first-time-contributor gate: a workflow triggered by a `pull_request` from 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.yml` will run on `e18c766`. 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 policy` clean at 182 files, `cargo test -p xtask --locked` 8 passed, `cargo test --workspace --locked` exit 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.
fuzeofficlal commented 2026-11-26 03:03:54 +00:00 (Migrated from github.com)

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 than MAX_ENCODED_RUN (512) bare byte-range (0..=255) decimal literals while restricting to <= 3 digits, 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-entry COEF0_LENS), floats, and addresses.
  • Passes the entire 63bcca43 repository cleanly (191 files ok).

Local verification:

  • cargo test --locked -p xtask: 8/8 passed
  • cargo clippy --locked -p xtask --tests -- -D warnings: 0 warnings
  • cargo xtask policy (using this PR's updated policy on 63bcca43): 191 files ok
<!-- greyfinch-sync:Marvisak/VIctory:review:6067593333 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2246#pullrequestreview-6067593333). Originally posted by [fuzeofficlal](https://github.com/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 than `MAX_ENCODED_RUN` (512) bare byte-range (`0..=255`) decimal literals while restricting to `<= 3` digits, 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-entry `COEF0_LENS`), floats, and addresses. - Passes the entire `63bcca43` repository cleanly (`191 files ok`). **Local verification**: - `cargo test --locked -p xtask`: **8/8 passed** - `cargo clippy --locked -p xtask --tests -- -D warnings`: 0 warnings - `cargo xtask policy` (using this PR's updated policy on `63bcca43`): `191 files ok`
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2246:upstream-pr/2246'
git switch 'upstream-pr/2246'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2246'
git switch 'upstream-pr/2246'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2246'
git switch 'upstream-pr/2246'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2246'
git switch 'main'
git merge --squash 'upstream-pr/2246'
git switch 'main'
git merge --ff-only 'upstream-pr/2246'
git switch 'main'
git merge 'upstream-pr/2246'
git push origin 'main'
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!2244
No description provided.