VICTORY_WRITE_SITES writes a game-derived file wherever it is pointed, without the ensure_outside_repo check every other writer performs #33

Closed
opened 2026-11-26 03:31:28 +00:00 by github-bot · 1 comment
Owner

@⁠itsonewi on GitHub · 2026-11-25 23:55 UTC · original

VICTORY_WRITE_SITES is the one path in the tree that writes a game-derived file wherever the user points it, and it is the one that skips the asset-policy check every other writer performs.

Where

crates/victory-gpu/src/titlewrite.rs:273-289 (learn, diagnostics builds with the switch set):

let Some(file) = std::env::var_os("VICTORY_WRITE_SITES") else { return; };
std::thread::spawn(move || {
    let Some((image, offset)) = place(rip) else { return; };
    ...
    if let Ok(mut file) = std::fs::OpenOptions::new().append(true).create(true).open(&file) {
        let _ = file.write_all(line.as_bytes());
    }

Every line written is <title module file name> <offset in it> — a title code address, which is exactly what docs/asset-policy.md and crates/victory-core/src/policy.rs:1-7 call game-derived:

"Everything VIctory produces from the user's files (converted assets, prepared images, shader caches, crash dumps) is as much 'from the game' as the files themselves. Every tool that writes such output must call ensure_outside_repo on the destination first."

The shader cache (victory-pipeline's Cache::open), the cache and data directories (config::subdir) and the crash log all go through that check. This one does not, so VICTORY_WRITE_SITES=victory.txt while the working directory is the checkout (which is what scripts/play.ps1 sets, Push-Location to the repository root) writes the file into the repository. cargo xtask policy only checks what git tracks, so the stray file sits there unnoticed until someone commits it.

Why it is not already handled

victory-gpu's manifest has no victory-core dependency at all (crates/victory-gpu/Cargo.toml:10-17: blake3, zlib-rs, tracing, anyhow, victory-formats, victory-pipeline, victory-shader). So ensure_outside_repo is not callable from this file today; the check has to come in through victory-pipeline (which has the cache that does call it) or a new dependency on victory-core.

Fix

Before opening the file: resolve it and refuse with one tracing::warn! when it is inside a source tree — either by exposing a small victory_pipeline::outside_repo(path) helper over victory_core::ensure_outside_repo, or by adding the dependency. The reader side (crates/victory-loader/src/write_sites.rs:287-291) is fine: reading a file the user names is not a write into the tree.

Not checked

Source reading at 0a43566. I did not run the title with the switch set, so the file appearing in a checkout is derived from the code (the path is used exactly as given) and not observed.

AI use

AI-assisted review (source reading). No build, no run, no game files.

**@⁠itsonewi** on GitHub · 2026-11-25 23:55 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/33) `VICTORY_WRITE_SITES` is the one path in the tree that writes a game-derived file wherever the user points it, and it is the one that skips the asset-policy check every other writer performs. ## Where `crates/victory-gpu/src/titlewrite.rs:273-289` (`learn`, diagnostics builds with the switch set): ```rust let Some(file) = std::env::var_os("VICTORY_WRITE_SITES") else { return; }; std::thread::spawn(move || { let Some((image, offset)) = place(rip) else { return; }; ... if let Ok(mut file) = std::fs::OpenOptions::new().append(true).create(true).open(&file) { let _ = file.write_all(line.as_bytes()); } ``` Every line written is `<title module file name> <offset in it>` — a title code address, which is exactly what `docs/asset-policy.md` and `crates/victory-core/src/policy.rs:1-7` call game-derived: > "Everything VIctory produces from the user's files (converted assets, prepared images, shader caches, crash dumps) is as much 'from the game' as the files themselves. Every tool that writes such output must call `ensure_outside_repo` on the destination first." The shader cache (`victory-pipeline`'s `Cache::open`), the cache and data directories (`config::subdir`) and the crash log all go through that check. This one does not, so `VICTORY_WRITE_SITES=victory.txt` while the working directory is the checkout (which is what `scripts/play.ps1` sets, `Push-Location` to the repository root) writes the file into the repository. `cargo xtask policy` only checks what git **tracks**, so the stray file sits there unnoticed until someone commits it. ## Why it is not already handled `victory-gpu`'s manifest has no `victory-core` dependency at all (`crates/victory-gpu/Cargo.toml:10-17`: blake3, zlib-rs, tracing, anyhow, victory-formats, victory-pipeline, victory-shader). So `ensure_outside_repo` is not callable from this file today; the check has to come in through `victory-pipeline` (which has the cache that does call it) or a new dependency on `victory-core`. ## Fix Before opening the file: resolve it and refuse with one `tracing::warn!` when it is inside a source tree — either by exposing a small `victory_pipeline::outside_repo(path)` helper over `victory_core::ensure_outside_repo`, or by adding the dependency. The reader side (`crates/victory-loader/src/write_sites.rs:287-291`) is fine: reading a file the user names is not a write into the tree. ## Not checked Source reading at `0a43566`. I did not run the title with the switch set, so the file appearing in a checkout is derived from the code (the path is used exactly as given) and not observed. ## AI use AI-assisted review (source reading). No build, no run, no game files.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:31:28 +00:00
Author
Owner

@⁠itsonewi on GitHub · 2026-11-26 00:07 UTC · original

A correction to my own report, after reading xtask/src/policy.rs: the check does not only look at tracked files, and the hole is worse than I described in a different way.

What I got wrong. list_files(root, false) runs git ls-files -z --cached --others --exclude-standard (xtask/src/policy.rs:120-126), so untracked files that are not ignored are checked. A victory.txt written into the checkout by VICTORY_WRITE_SITES would be looked at, not skipped.

What that changes. The file would still be accepted, because the check is an allowlist over names, sizes and text shape:

  • txt is on ALLOWED_EXTENSIONS (:17-19), so a .txt name passes.
  • <module file name> <offset> lines are small, contain no NUL byte and no run of more than MAX_ENCODED_RUN = 512 alphanumerics (:169-182), so the content passes too.

So the asset-policy check is not a defence here at all: a text file of title code offsets is exactly the shape it is designed to let through, on purpose, because prose and source are that shape. That makes the missing ensure_outside_repo in titlewrite.rs:273-289 the only guard, and it is the one that is absent.

What I would keep from the original report. Everything about the write path: no check, victory-gpu cannot call ensure_outside_repo because it has no victory-core dependency (crates/victory-gpu/Cargo.toml:10-17), and scripts/play.ps1 sets the working directory to the repository root, so a relative path lands in the tree.

One extra consequence now visible from policy.rs. Because EXCEPTIONS is keyed on an exact path string (:32-35) and MAX_FILE_SIZE is 640 KiB, adding a second exception would be the path of least resistance for a future contributor who hits this — which is why the guard belongs in the writer, not in the policy's allowlist.

(Self-correction, written with AI assistance, from xtask/src/policy.rs and crates/victory-gpu/src/titlewrite.rs at 0a43566.)

**@⁠itsonewi** on GitHub · 2026-11-26 00:07 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/33#issuecomment-7178423510) A correction to my own report, after reading `xtask/src/policy.rs`: the check does **not** only look at tracked files, and the hole is worse than I described in a different way. **What I got wrong.** `list_files(root, false)` runs `git ls-files -z --cached --others --exclude-standard` (`xtask/src/policy.rs:120-126`), so untracked files that are not ignored *are* checked. A `victory.txt` written into the checkout by `VICTORY_WRITE_SITES` would be looked at, not skipped. **What that changes.** The file would still be accepted, because the check is an allowlist over names, sizes and text shape: - `txt` is on `ALLOWED_EXTENSIONS` (`:17-19`), so a `.txt` name passes. - `<module file name> <offset>` lines are small, contain no NUL byte and no run of more than `MAX_ENCODED_RUN = 512` alphanumerics (`:169-182`), so the content passes too. So the asset-policy check is not a defence here at all: a text file of title code offsets is exactly the shape it is designed to let through, on purpose, because prose and source are that shape. That makes the missing `ensure_outside_repo` in `titlewrite.rs:273-289` the only guard, and it is the one that is absent. **What I would keep from the original report.** Everything about the write path: no check, `victory-gpu` cannot call `ensure_outside_repo` because it has no `victory-core` dependency (`crates/victory-gpu/Cargo.toml:10-17`), and `scripts/play.ps1` sets the working directory to the repository root, so a relative path lands in the tree. **One extra consequence now visible from `policy.rs`.** Because `EXCEPTIONS` is keyed on an exact path string (`:32-35`) and `MAX_FILE_SIZE` is 640 KiB, adding a second exception would be the path of least resistance for a future contributor who hits this — which is why the guard belongs in the writer, not in the policy's allowlist. (Self-correction, written with AI assistance, from `xtask/src/policy.rs` and `crates/victory-gpu/src/titlewrite.rs` at `0a43566`.)
This discussion has been locked. Commenting is limited to contributors.
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/avatarmanz--VIctory-7900XTX#33
No description provided.