translate: refuse a VICTORY_EMIT_DUMP directory inside the repo
translate writes emitted DXIL and validator reports to the VICTORY_EMIT_DUMP directory. Both are derived from the game's shaders, but the directory was never checked against the source tree. With VICTORY_EMIT_DUMP=. run from the checkout, the .txt reports land in the repo, and git and cargo xtask policy both let them through. Check the directory once at the start of translate::run, as Config already does for the cache and data directories. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 988fd9a64718ee9a235cff3b60192b6b86006c4d)
This commit is contained in:
1 parent
81fa73c2aa
commit
20602d4b13
1 file changed
+25
@@ -240,6 +240,10 @@ pub fn run(
|
||||
list: bool,
|
||||
jobs: Option<usize>,
|
||||
) -> Result<()> {
|
||||
// Dumped shaders and validator reports are game-derived (rule #1).
|
||||
if let Some(dir) = std::env::var_os("VICTORY_EMIT_DUMP") {
|
||||
victory_core::ensure_outside_repo(Path::new(&dir))?;
|
||||
}
|
||||
let paths = crate::default_paths(paths)?;
|
||||
// `VICTORY_HOST_MAX_WAVE=32`: translate as for a host whose waves have
|
||||
// at most 32 lanes (as the runtime does on such a card).
|
||||
@@ -931,3 +935,24 @@ fn tally_structured(program: &ir::Program, s: &structure::Structured, t: &mut Ta
|
||||
fn lock<T>(m: &Mutex<T>) -> std::sync::MutexGuard<'_, T> {
|
||||
m.lock().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
/// Shader dumps are game-derived, so a dump directory in the repo is refused.
|
||||
#[test]
|
||||
fn emit_dump_inside_repo_is_refused() {
|
||||
// SAFETY: no other test in this binary touches the environment.
|
||||
unsafe { std::env::set_var("VICTORY_EMIT_DUMP", env!("CARGO_MANIFEST_DIR")) };
|
||||
let missing = std::env::temp_dir().join("victory-translate-no-such-dir");
|
||||
let err = super::run(vec![missing], false, false, false, Some(1)).unwrap_err();
|
||||
// SAFETY: as above; unset so a later test's `run` is not refused.
|
||||
unsafe { std::env::remove_var("VICTORY_EMIT_DUMP") };
|
||||
assert!(
|
||||
matches!(
|
||||
err.downcast_ref(),
|
||||
Some(victory_core::PolicyError::InsideRepo { .. })
|
||||
),
|
||||
"{err}"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user