Policy: a path with .. below a directory not yet created resolves #252

Closed
SkippySteve wants to merge 1 commit from upstream-pr/252 into main
SkippySteve commented 2026-11-24 01:50:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T01:50:46Z.


ensure_outside_repo resolves a destination that does not exist yet by walking up to its longest existing prefix, canonicalizing that, and re-appending the rest. The walk takes each component with Path::file_name, which is None for a path ending in ... So a destination with .. below a directory that is not created yet, such as <tmp>/missing/../cache, fails with

cannot resolve /tmp/.tmpXXXX/missing/../cache: No such file or directory (os error 2)

instead of being checked. A cache or data directory configured that way is refused even though it is outside the repository (Cache::open, the config's subdir, and victory config report it as an error).

The fix takes the last component with components().next_back() and accepts both normal names and ..; the tail is already normalized lexically afterwards, so missing/../cache becomes cache under the canonical prefix. Root and prefix components still end the walk with the same error as before.

The new test resolves_dotdot_after_a_missing_directory checks that <tmp>/missing/../cache is accepted and that <repo>/not-yet-created/../out is reported as InsideRepo (it was an Io error before). It fails on main and passes with the fix.

cargo test -p victory-core and cargo clippy -p victory-core --all-targets pass (on Linux). config.rs is not touched.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572775547 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/252). Originally posted by [SkippySteve](https://github.com/SkippySteve) on 2026-11-24T01:50:46Z. --- `ensure_outside_repo` resolves a destination that does not exist yet by walking up to its longest existing prefix, canonicalizing that, and re-appending the rest. The walk takes each component with `Path::file_name`, which is `None` for a path ending in `..`. So a destination with `..` below a directory that is not created yet, such as `<tmp>/missing/../cache`, fails with ``` cannot resolve /tmp/.tmpXXXX/missing/../cache: No such file or directory (os error 2) ``` instead of being checked. A cache or data directory configured that way is refused even though it is outside the repository (`Cache::open`, the config's `subdir`, and `victory config` report it as an error). The fix takes the last component with `components().next_back()` and accepts both normal names and `..`; the tail is already normalized lexically afterwards, so `missing/../cache` becomes `cache` under the canonical prefix. Root and prefix components still end the walk with the same error as before. The new test `resolves_dotdot_after_a_missing_directory` checks that `<tmp>/missing/../cache` is accepted and that `<repo>/not-yet-created/../out` is reported as `InsideRepo` (it was an `Io` error before). It fails on `main` and passes with the fix. `cargo test -p victory-core` and `cargo clippy -p victory-core --all-targets` pass (on Linux). `config.rs` is not touched.
upstream-sync closed this pull request 2026-11-24 06:52:04 +00:00
SkippySteve commented 2026-11-24 06:55:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T02:28:11Z.


Superseded by #246, which now includes this change (rebased onto main, with its test).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7120175051 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/252#issuecomment-7120175051). Originally posted by [SkippySteve](https://github.com/SkippySteve) on 2026-11-24T02:28:11Z. --- Superseded by #246, which now includes this change (rebased onto main, with its test).

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!252
No description provided.