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

Open
github-bot wants to merge 2 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
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.