Policy: resolve a .. in the not-yet-existing part of a path (port of VIctory#937) #53

Open
github-bot wants to merge 0 commits from github-bot/gh-53 into main AGit
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 20:53 UTC · original
lcg007xd-c:port/policy-dotdot → main · +13 −0 · 1 files · 2 commits · open

What

policy::resolve canonicalizes the longest existing prefix of a path and re-appends the rest, so not-yet-created directories can be checked. It walks up with Path::file_name(), which is None for a trailing ...

So a cache_dir or data_dir such as <somewhere>/new/../cache (nothing created yet) hit the _ arm and failed with PolicyError::Io instead of being resolved. A trailing .. is now kept in the re-appended tail, and normalize resolves it lexically, as its doc comment already says.

This also matters for the new is_within check from #42, which compares resolved paths that may not exist yet. Without this change, a data_dir with a .. in its missing part makes that check fail with an I/O error.

Port

Cherry-pick (-x) of github.com/Marvisak/VIctory@52f0a09 from upstream https://github.com/Marvisak/VIctory/pull/937. nino-exe is still the commit author. It applied cleanly.

Test

resolves_dot_dot_in_a_path_that_does_not_exist_yet fails on main (the expect on resolve) and passes with this change.

How this was checked (Linux, no Windows PC or game files)

  • The portable CI commands pass locally on this branch: cargo clippy -p victory-core -p victory-pe -p victory-pipeline -p victory-shader -p victory-formats -p victory-game -p xtask --all-targets --locked -- -D warnings, then cargo test on the same crates (rebased on current main).
  • cargo clippy with the same crates and --target x86_64-pc-windows-msvc (check only, no link) is clean.
  • rustfmt --check is clean on the changed file.

Not tested: Windows runtime, GPU (D3D12/DXIL validation) and the game itself.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 20:53 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/53) `lcg007xd-c:port/policy-dotdot` → `main` · +13 −0 · 1 files · 2 commits · open ## What `policy::resolve` canonicalizes the longest existing prefix of a path and re-appends the rest, so not-yet-created directories can be checked. It walks up with `Path::file_name()`, which is `None` for a trailing `..`. So a `cache_dir` or `data_dir` such as `<somewhere>/new/../cache` (nothing created yet) hit the `_` arm and failed with `PolicyError::Io` instead of being resolved. A trailing `..` is now kept in the re-appended tail, and `normalize` resolves it lexically, as its doc comment already says. This also matters for the new `is_within` check from #42, which compares `resolve`d paths that may not exist yet. Without this change, a `data_dir` with a `..` in its missing part makes that check fail with an I/O error. ## Port Cherry-pick (`-x`) of https://github.com/Marvisak/VIctory/commit/52f0a09 from upstream https://github.com/Marvisak/VIctory/pull/937. nino-exe is still the commit author. It applied cleanly. ## Test `resolves_dot_dot_in_a_path_that_does_not_exist_yet` fails on `main` (the `expect` on `resolve`) and passes with this change. ## How this was checked (Linux, no Windows PC or game files) - The portable CI commands pass locally on this branch: `cargo clippy -p victory-core -p victory-pe -p victory-pipeline -p victory-shader -p victory-formats -p victory-game -p xtask --all-targets --locked -- -D warnings`, then `cargo test` on the same crates (rebased on current `main`). - `cargo clippy` with the same crates and `--target x86_64-pc-windows-msvc` (check only, no link) is clean. - `rustfmt --check` is clean on the changed file. Not tested: Windows runtime, GPU (D3D12/DXIL validation) and the game itself. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`resolve` canonicalizes the longest existing prefix and re-appends the rest, but it walks up with
`Path::file_name()`, which is None for a trailing `..`. A path such as `<tmp>/a/../b` (nothing exists yet) hit the
`_` arm and returned PolicyError::Io, so a cache_dir or data_dir with a `..` in a directory that does not exist yet
was rejected, and `normalize`'s `..` handling for the missing tail was never reached.

A trailing `..` is now kept in `rest` so `normalize` resolves it lexically.

Test: resolves_dot_dot_in_a_path_that_does_not_exist_yet (fails before, passes after). cargo test -p victory-core,
cargo fmt --check and cargo clippy --tests are clean.

(cherry picked from commit 52f0a099ede8aa4d5bde61a0c46963a77a4378ba)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:42:40 +00:00
Author
Owner

@⁠lmouz823-lang on GitHub · 2026-11-28 04:10 UTC · original

I can take native Windows path-resolution validation at exact head 3d6f1247cd82e7cba869c166b0d42aa7f946ec51. I will run the missing-tail dot-dot regression, temporarily remove only the new tail-handling branch to check the expected failure, then restore and recompile. I will also check the core library tests and isolate the regression with a private temporary directory if needed to guarantee that its path suffix is missing. Exact results and any small test-only diff will follow here. AI-assisted with Codex.

**@⁠lmouz823-lang** on GitHub · 2026-11-28 04:10 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/53#issuecomment-7233774952) I can take native Windows path-resolution validation at exact head `3d6f1247cd82e7cba869c166b0d42aa7f946ec51`. I will run the missing-tail dot-dot regression, temporarily remove only the new tail-handling branch to check the expected failure, then restore and recompile. I will also check the core library tests and isolate the regression with a private temporary directory if needed to guarantee that its path suffix is missing. Exact results and any small test-only diff will follow here. AI-assisted with Codex.
Author
Owner

@⁠lmouz823-lang on GitHub · 2026-11-28 04:17 UTC · original

Native Windows/MSVC validation completed on exact head 3d6f1247cd82e7cba869c166b0d42aa7f946ec51 using Rust 1.98.1, the default test profile and an isolated target directory.

The original policy::tests::resolves_dot_dot_in_a_path_that_does_not_exist_yet regression executed one test and passed. Temporarily removing only the added trailing-.. match branch made it fail with PolicyError::Io / NotFound (exit 101). Restoring the exact head triggered recompilation and the test passed again.

I also strengthened that existing regression to use its own tempfile::tempdir(), with an asserted-missing not-created base and a / b children. Its expected path is built directly from the canonical existing temporary directory plus not-created/b, making the missing-path precondition deterministic and checking the result against an independent expected value.

The strengthened test passes on Windows. Removing the same branch makes it fail with Io / NotFound too, confirming that Windows path canonicalization does exercise the changed branch. After restoring and recompiling the final source, the exact regression passes, all 5 policy tests pass, and the complete 15-test victory-core --lib suite passes with 0 failed, 0 ignored and 0 filtered out.

The final proposed diff changes only the existing test, +10/-2 lines. rustfmt --check on the changed file, cargo clippy --locked -p victory-core --all-targets -- -D warnings, and git diff --check pass.

Reproduction commands follow.

cargo test --locked -p victory-core --lib policy::tests::resolves_dot_dot_in_a_path_that_does_not_exist_yet -- --exact --nocapture --test-threads=1
cargo test --locked -p victory-core --lib policy::tests:: -- --nocapture --test-threads=1
cargo test --locked -p victory-core --lib -- --nocapture --test-threads=1

These checks cover native Windows path resolution with synthetic temporary directories. AI assistance from Codex covered the test, execution and this report.

Test-only independent missing-tail regression
diff --git a/crates/victory-core/src/policy.rs b/crates/victory-core/src/policy.rs
index 97a3989..eed9b5a 100644
--- a/crates/victory-core/src/policy.rs
+++ b/crates/victory-core/src/policy.rs
@@ -171,9 +171,17 @@ mod tests {
 
     #[test]
     fn resolves_dot_dot_in_a_path_that_does_not_exist_yet() {
-        let base = std::env::temp_dir().join("victory-policy-no-such");
+        let tmp = tempfile::tempdir().unwrap();
+        let base = tmp.path().join("not-created");
+        assert!(!base.exists());
         let path = base.join("a").join("..").join("b");
+        assert!(!base.join("a").exists());
+        assert!(!base.join("b").exists());
+        let expected = std::fs::canonicalize(tmp.path())
+            .unwrap()
+            .join("not-created")
+            .join("b");
         let resolved = resolve(&path).expect("a `..` in the missing tail must resolve lexically");
-        assert_eq!(resolved, resolve(&base.join("b")).unwrap());
+        assert_eq!(resolved, expected);
     }
 }
**@⁠lmouz823-lang** on GitHub · 2026-11-28 04:17 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/53#issuecomment-7233894722) Native Windows/MSVC validation completed on exact head `3d6f1247cd82e7cba869c166b0d42aa7f946ec51` using Rust 1.98.1, the default test profile and an isolated target directory. The original `policy::tests::resolves_dot_dot_in_a_path_that_does_not_exist_yet` regression executed one test and passed. Temporarily removing only the added trailing-`..` match branch made it fail with `PolicyError::Io` / `NotFound` (exit 101). Restoring the exact head triggered recompilation and the test passed again. I also strengthened that existing regression to use its own `tempfile::tempdir()`, with an asserted-missing `not-created` base and `a` / `b` children. Its expected path is built directly from the canonical existing temporary directory plus `not-created/b`, making the missing-path precondition deterministic and checking the result against an independent expected value. The strengthened test passes on Windows. Removing the same branch makes it fail with `Io` / `NotFound` too, confirming that Windows path canonicalization does exercise the changed branch. After restoring and recompiling the final source, the exact regression passes, all **5 policy tests pass**, and the complete **15-test `victory-core --lib` suite passes with 0 failed, 0 ignored and 0 filtered out**. The final proposed diff changes only the existing test, **+10/-2 lines**. `rustfmt --check` on the changed file, `cargo clippy --locked -p victory-core --all-targets -- -D warnings`, and `git diff --check` pass. Reproduction commands follow. ```powershell cargo test --locked -p victory-core --lib policy::tests::resolves_dot_dot_in_a_path_that_does_not_exist_yet -- --exact --nocapture --test-threads=1 cargo test --locked -p victory-core --lib policy::tests:: -- --nocapture --test-threads=1 cargo test --locked -p victory-core --lib -- --nocapture --test-threads=1 ``` These checks cover native Windows path resolution with synthetic temporary directories. AI assistance from Codex covered the test, execution and this report. <details> <summary>Test-only independent missing-tail regression</summary> ```diff diff --git a/crates/victory-core/src/policy.rs b/crates/victory-core/src/policy.rs index 97a3989..eed9b5a 100644 --- a/crates/victory-core/src/policy.rs +++ b/crates/victory-core/src/policy.rs @@ -171,9 +171,17 @@ mod tests { #[test] fn resolves_dot_dot_in_a_path_that_does_not_exist_yet() { - let base = std::env::temp_dir().join("victory-policy-no-such"); + let tmp = tempfile::tempdir().unwrap(); + let base = tmp.path().join("not-created"); + assert!(!base.exists()); let path = base.join("a").join("..").join("b"); + assert!(!base.join("a").exists()); + assert!(!base.join("b").exists()); + let expected = std::fs::canonicalize(tmp.path()) + .unwrap() + .join("not-created") + .join("b"); let resolved = resolve(&path).expect("a `..` in the missing tail must resolve lexically"); - assert_eq!(resolved, resolve(&base.join("b")).unwrap()); + assert_eq!(resolved, expected); } } ``` </details>
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/53/head:github-bot/gh-53'
git switch 'github-bot/gh-53'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-53'
git switch 'github-bot/gh-53'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-53'
git switch 'github-bot/gh-53'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-53'
git switch 'main'
git merge --squash 'github-bot/gh-53'
git switch 'main'
git merge --ff-only 'github-bot/gh-53'
git switch 'main'
git merge 'github-bot/gh-53'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.