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

Open
github-bot wants to merge 1 commit from github-bot/gh-2246 into main AGit
Owner

@⁠xiaotu030202 on GitHub · 2026-11-25 08:46 UTC · original
xiaotu030202:xtask/policy-decimal-byte-arrays → main · +123 −1 · 1 files · 1 commits · open

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.

**@⁠xiaotu030202** on GitHub · 2026-11-25 08:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2246) `xiaotu030202:xtask/policy-decimal-byte-arrays` → `main` · +123 −1 · 1 files · 1 commits · open ## 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.
`check` 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, so the note

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

stood in for the rule. Add it.

`longest_decimal_run` counts byte-range literals (at most three digits, no
leading zero, no type suffix or fraction, nothing but a separator between
them) in one unbroken run, and `check` rejects a run longer than
`MAX_ENCODED_RUN`, the limit the hex rules already use.

Counted in literals rather than digits, so the tables a decoder needs stay
legal: the largest byte-sized table in the tree is `COEF0_LENS` at 272
entries, and the whole tree peaks at 272, well under 512.

Tests: the `[77, 90, ...]` shape is now rejected both comma-separated on
one line and one entry per line; `COEF0_LENS`- and `COEF0_SYMS`-shaped
tables still pass, as do `1u8` suffixes, fractions and leading zeros.

Signed-off-by: xiaotu030202 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:59:50 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 09:25 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 09:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2246#issuecomment-7158310303) 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.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 10:29 UTC · original

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.

**@⁠cloph-dsp** on GitHub · 2026-11-25 10:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2246#issuecomment-7159761914) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:31 UTC · original · edited 2026-11-25 16:46 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 13:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2246#issuecomment-7163908813) · edited 2026-11-25 16:46 UTC <!-- 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)_
Author
Owner

@⁠xiaotu030202 on GitHub · 2026-11-25 15:38 UTC · original

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.

**@⁠xiaotu030202** on GitHub · 2026-11-25 15:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2246#issuecomment-7167145003) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2246/head:github-bot/gh-2246'
git switch 'github-bot/gh-2246'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2246'
git switch 'github-bot/gh-2246'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2246'
git switch 'github-bot/gh-2246'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2246'
git switch 'main'
git merge --squash 'github-bot/gh-2246'
git switch 'main'
git merge --ff-only 'github-bot/gh-2246'
git switch 'main'
git merge 'github-bot/gh-2246'
git push origin 'main'
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!2246
No description provided.