[pr-fix] policy: a payload wrapped at the encoder's line width is caught #376

Open
qnjk wants to merge 1 commit from qnjk/Darner:policy-wrapped-payload into main
First-time contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: longest_encoded_run split the content at every byte outside the base64 alphabet and compared the longest fragment with MAX_ENCODED_RUN (512):

    let is_payload = |b: &u8| b.is_ascii_alphanumeric() || matches!(b, b'+' | b'/' | b'=');
    content.split(|b| !is_payload(b)).map(<[u8]>::len).max()
    

    (xtask/src/policy.rs:213-215). A line break is not payload, so a payload that an encoder wrapped has no fragment longer than one line: GNU base64 and Python's base64.encodebytes wrap at 76 columns and openssl base64 at 64, all far under 512. Any wrapped dump written into a file type the policy allows (txt, md, json are on the list) passed. Reproduced with 4096 synthetic bytes ((i*37+11) % 256) as base64: 5464 characters unbroken is refused (5464-character hex/base64 run), the same characters wrapped at 76 columns returned no problem. This check is the static enforcement of the repository's first rule — nothing from the game is ever committed — so a way around it matters more than its size suggests.

  • This change joins a group of lines back into one run when every line of the group is wholly payload and at least as wide as an encoder's line (WRAPPED_LINE, 24). A wrapped payload is therefore one run again, while wrapped prose (words, spaces) and single-character lines still end the runs they are in. Nothing else in the policy changes.

How it was tested

  • Tested revision: 5b778e0 (one commit on f3840d7).

  • Commands and results:

    • cargo test --locked -p xtask — 9 passed, 0 failed.
    • cargo xtask policy over this tree — asset policy: 555 files ok, so the new rule does not trip anything the repository actually tracks (repository_passes_policy is the unit test for that and still passes).
    • The new test policy::tests::rejects_data_smuggled_across_line_breaks was run against the same tree with only the old function body restored: it fails there with 4096 characters of base64 wrapped at 76 columns passed, and passes with the change. The same test asserts that wrapped prose is still accepted and that the unbroken payload is still refused, so it pins the rule and not just the new code.
    • cargo clippy --locked -p xtask --all-targets -- -D warnings passes.
  • Changes a default: no. The repository is policy-clean both before and after; what changes is that a wrapped payload is now refused.

  • A/B result, for a change of a default (on for everyone) or a speed claim: not applicable — no default changes and no speed claim.

  • Gates run on that revision:

    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not green on this machine, and not because of this change. Three pre-existing failures, each covered by an open pull request: darner-gpu stands still in parallel on the test deadlock #224 describes, and serially it finishes 1772 passed and 1 failed (pipeline::make::tests::a_capped_draw_waits_once_then_drops, which passes on its own) beside the order-dependent watch::tests::ask_once_by_res_splits_reservations_without_refusals and texture::ahead::tests::drain_waits_until_then_callbacks_have_run flakes that #150 is about; darner-shader fails emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, whose fixture #227 fixes. Every other crate passes. This change touches no file of either crate.
  • Gameplay, when relevant: not applicable — this is the pre-commit policy checker, it never runs while the title runs.

  • Shader wave sizes tested, when relevant: not applicable.

  • Hardware dependence: none.

  • Coverage gaps: xxd/hexdump-shaped dumps (an offset column plus 4-digit groups) are still not caught by the encoded-run check; that is a different shape from a wrapped payload and it is not part of this change. The longest legal base64-ish fixture in the tree is unchanged.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not applicable: this is the static asset-policy checker (cargo xtask policy), which never runs while the title runs. It was run over the whole tree instead: 555 files ok.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md. (cargo xtask policy: 555 files ok.)
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found. No open pull request changes any file under xtask/ (checked against the file list of all 161 open pull requests), and no open or closed issue or pull request body mentions longest_encoded_run, MAX_ENCODED_RUN or a wrapped payload.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: `longest_encoded_run` split the content at every byte outside the base64 alphabet and compared the longest fragment with `MAX_ENCODED_RUN` (512): ```rust let is_payload = |b: &u8| b.is_ascii_alphanumeric() || matches!(b, b'+' | b'/' | b'='); content.split(|b| !is_payload(b)).map(<[u8]>::len).max() ``` (`xtask/src/policy.rs:213-215`). A line break is not payload, so a payload that an encoder wrapped has no fragment longer than one line: GNU `base64` and Python's `base64.encodebytes` wrap at 76 columns and `openssl base64` at 64, all far under 512. Any wrapped dump written into a file type the policy allows (`txt`, `md`, `json` are on the list) passed. Reproduced with 4096 synthetic bytes (`(i*37+11) % 256`) as base64: 5464 characters unbroken is refused (`5464-character hex/base64 run`), the same characters wrapped at 76 columns returned no problem. This check is the static enforcement of the repository's first rule — nothing from the game is ever committed — so a way around it matters more than its size suggests. - This change joins a group of lines back into one run when every line of the group is wholly payload and at least as wide as an encoder's line (`WRAPPED_LINE`, 24). A wrapped payload is therefore one run again, while wrapped prose (words, spaces) and single-character lines still end the runs they are in. Nothing else in the policy changes. ## How it was tested - Tested revision: `5b778e0` (one commit on `f3840d7`). - Commands and results: - `cargo test --locked -p xtask` — 9 passed, 0 failed. - `cargo xtask policy` over this tree — `asset policy: 555 files ok`, so the new rule does not trip anything the repository actually tracks (`repository_passes_policy` is the unit test for that and still passes). - The new test `policy::tests::rejects_data_smuggled_across_line_breaks` was run against the same tree with only the old function body restored: it fails there with `4096 characters of base64 wrapped at 76 columns passed`, and passes with the change. The same test asserts that wrapped prose is still accepted and that the unbroken payload is still refused, so it pins the rule and not just the new code. - `cargo clippy --locked -p xtask --all-targets -- -D warnings` passes. - Changes a default: no. The repository is policy-clean both before and after; what changes is that a wrapped payload is now refused. - A/B result, for a change of a default (on for everyone) or a speed claim: not applicable — no default changes and no speed claim. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: **not green on this machine, and not because of this change.** Three pre-existing failures, each covered by an open pull request: `darner-gpu` stands still in parallel on the test deadlock #224 describes, and serially it finishes 1772 passed and 1 failed (`pipeline::make::tests::a_capped_draw_waits_once_then_drops`, which passes on its own) beside the order-dependent `watch::tests::ask_once_by_res_splits_reservations_without_refusals` and `texture::ahead::tests::drain_waits_until_then_callbacks_have_run` flakes that #150 is about; `darner-shader` fails `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`, whose fixture #227 fixes. Every other crate passes. This change touches no file of either crate. - Gameplay, when relevant: not applicable — this is the pre-commit policy checker, it never runs while the title runs. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: `xxd`/`hexdump`-shaped dumps (an offset column plus 4-digit groups) are still not caught by the encoded-run check; that is a different shape from a wrapped payload and it is not part of this change. The longest legal base64-ish fixture in the tree is unchanged. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not applicable: this is the static asset-policy checker (`cargo xtask policy`), which never runs while the title runs. It was run over the whole tree instead: 555 files ok. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. (`cargo xtask policy`: 555 files ok.) - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. No open pull request changes any file under `xtask/` (checked against the file list of all 161 open pull requests), and no open or closed issue or pull request body mentions `longest_encoded_run`, `MAX_ENCODED_RUN` or a wrapped payload. - Replaces or overlaps: none found
`longest_encoded_run` split the file at every byte outside the base64
alphabet and took the longest fragment, so a payload the encoder wrapped
had no fragment longer than its line: GNU `base64` and Python's
`encodebytes` wrap at 76 columns and `openssl base64` at 64, all far
under `MAX_ENCODED_RUN` (512). Any wrapped dump written to an allowed
file type passed the check, and this check is the static half of the
rule that nothing from the game is ever committed.

Lines are now joined back when every line of the group is wholly payload
and at least as wide as an encoder's line, so a wrapped payload counts as
one run while wrapped prose and single-character lines stay prose.

The test wraps 4096 synthetic characters at 76 columns: it passes the
check on main and is caught here. `repository_passes_policy` still passes
over the tree (555 files), so nothing in it trips the new rule.
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 'policy-wrapped-payload:qnjk-policy-wrapped-payload'
git switch 'qnjk-policy-wrapped-payload'

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 'qnjk-policy-wrapped-payload'
git switch 'qnjk-policy-wrapped-payload'
git rebase 'main'
git switch 'main'
git merge --ff-only 'qnjk-policy-wrapped-payload'
git switch 'qnjk-policy-wrapped-payload'
git rebase 'main'
git switch 'main'
git merge --no-ff 'qnjk-policy-wrapped-payload'
git switch 'main'
git merge --squash 'qnjk-policy-wrapped-payload'
git switch 'main'
git merge --ff-only 'qnjk-policy-wrapped-payload'
git switch 'main'
git merge 'qnjk-policy-wrapped-payload'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
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
TrustNo1/Darner!376
No description provided.