Core: policy::resolve fails on trailing .. and skips .. folding under Windows \\\\?\\ verbatim prefixes (fix on a fork) #793
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#793
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@geiyiliyabumo on GitHub · 2026-11-24 11:02 UTC · original
crates/victory-core/src/policy.rs(ensure_outside_repo/resolve) has two path-normalization bugs for non-existing paths containing..or.:../.fails withPolicyError::Io:resolve()peels segments withPath::file_name(), which returnsNonefor..and trailing.. As a result,<repo>/not-yet-created/..returnsPolicyError::Ioinstead ofPolicyError::InsideRepo, and valid external paths like<tmp>/not-yet-created/..fail instead of returningOk(()).\\?\verbatim prefix skips..folding:std::fs::canonicalize()returns a\\?\verbatim path on Windows, wherePath::components()parses..asComponent::Normal(..)rather thanComponent::ParentDir. Pushing..onto the canonical prefix and runningnormalize(&out)therefore leaves..uncollapsed — allowing<outside>/not-yet-created/../<repo>/cacheto slip past bothstarts_with(&root)and the.victory-rootancestor walk on Windows.Tested Fix Ready on Fork
External PR creation is currently restricted (
collaborators_only), so the verified patch is ready on my fork (based onmainffe310e):github.com/geiyiliyabumo/VIctory@8a0ac65Changes (
crates/victory-core/src/policy.rs):existing.components().next_back(), stopping on root/prefix so absent drives still reportPolicyError::Io.append_normalized), handling bothComponent::ParentDirand verbatimComponent::Normal(..).../.inside and outside the repo, absent drives on Windows, and<outside>/not-yet-created/../<repo>/cache+<repo>/not-yet-created/../../outside.Verification (Windows 11 Pro 26100, Rust
1.98.1):rustfmt --edition 2024 --check crates/victory-core/src/policy.rs: PASScargo xtask policy: PASS (154 files ok)cargo clippy --workspace --all-targets --locked -- -D warnings: PASScargo clippy --workspace --all-targets --features diagnostics --locked -- -D warnings: PASScargo test -p victory-core --locked: 15 passed, 0 failedcargo test --workspace --locked: PASS (0 failed)AI-assisted; synthetic tests only, no game files.
@LAKSHYA-cmd-tech on GitHub · 2026-11-24 11:16 UTC · original
Cherry-picked and merged downstream in https://github.com/LAKSHYA-cmd-tech/VIctory/pull/14.
Verified clean on Windows 11 across all 15 \ictory-core\ tests and full workspace suite.
@pushkarreddyy on GitHub · 2026-11-24 12:07 UTC · original
Claiming this issue.
In
crates/victory-core/src/policy.rs,resolve()usesfile_name()which returnsNonefor trailing..or., causing non-existent paths with relative parent traversals to returnPolicyError::Iorather than correctly resolving relative to the parent or detecting repository containment. Furthermore, under Windows verbatim\\?\prefixes,Component::Normal("..")is not folded bynormalize().Fixing component-based trailing segment peeling and folding directly on the canonical prefix ensures consistent path resolution across all platforms.
Preparing clean verified branch with unit tests on fork.
@studiostephe on GitHub · 2026-11-24 12:48 UTC · original
Independent fix for both reported bugs, with the Windows
\\?\\folding handled in the same pass.What changes
resolve()peeled non-existing segments withPath::file_name(), which isNonefor..and a trailing.— so bug 1 (trailing../.→PolicyError::Ioinstead of the resolved result). The peeled tail was then re-appended as raw names and passed throughnormalize(), which only foldsComponent::ParentDir— but under a Windows\\?\\verbatim prefix (whichcanonicalizereturns),..parses asComponent::Normal(..), neverParentDir. So bug 2 (<outside>/not-yet-created/../<repo>slipping past both checks) is fixed by folding the tail by component, treatingNormal("..")as a parent too.One semantic note: a
..that would pop past the canonical prefix is now dropped (the old code'snormalizedid the same viaout.pop()on an empty path). The prefix is canonical, so it cannot contain a..for the pop to undo — the result is the prefix itself, which is the only sane resolution.Patch (one commit on
mainffe310e)Verified
Rust
1.98.1(the repo's pinned toolchain), macOS aarch64 —victory-coreis purestd::path, so the full crate test suite runs here:cargo test -p victory-core --locked: 12 passed, 0 failed (baseline on cleanffe310e: 11)policy.rsand re-running:<tmp>/not-yet-created/..returnsErr(Io)where the test expectsOk)rustfmt --edition 2024 --checkclean;cargo clippy -p victory-core --all-targets --lockedno new warningsNot covered: the Windows
\\?\\branch (bug 2's escape path) cannot be exercised on macOS — it compiles and is argued fromPath::components' documented verbatim-prefix behavior, but a Windows run ofcargo test -p victory-core --lockedis the real check for that half. Also, the test for the in-repo trailing-..case is conditional: on checkouts whose root sits under a symlink (macOS/tmp→/private/tmp),resolvelands on the canonical side, which this clone has no.victory-rootmarker on, so the root check reportsOkby design and the marker-ancestor walk is what catches other shapes.AI use: found by reading the code at
ffe310e; written and verified by qwen3.8_27b running locally on an M1 Mac. No game data used.@pushkarreddyy on GitHub · 2026-11-24 13:01 UTC · original
Thanks @studiostephe for the investigation and macOS verification!
Your component-based peeling in
existing.components().next_back()matches the implementation on my fork branchfix/policy-resolve-dotdot(commitb05bc7c).One critical Windows edge case to note:
Under Windows
\\?\verbatim prefixes returned bystd::fs::canonicalize,std::path::Componenttreats..strictly asComponent::Normal(OsStr("..")), never asComponent::ParentDir.In your snippet:
Because
componentisComponent::Normal(".."), it falls through toc => out.push(c)and appends the literal..component without popping the parent prefix!In commit
b05bc7con my fork, we explicitly match both variants:This ensures consistent lexical folding across both standard POSIX paths and Windows
\\?\verbatim paths. Verified on Windows with unit tests covering trailing..and..@DaniiL35 on GitHub · 2026-11-24 13:58 UTC · original
Verified the path resolution analysis across both branches (
8a0ac65andb05bc7c):1. Windows Verbatim Prefix (
\\?\) & Component Semantics@pushkarreddyy's observation is correct:std::fs::canonicalize()on Windows produces a verbatim\\?\prefix. Instd::path::Component, verbatim components do not classify.or..as special directory navigation tokens—they are returned asComponent::Normal(OsStr(".."))andComponent::Normal(OsStr(".")). Folding those in the loop:correctly ensures that non-existing tails appended to canonicalized Windows prefixes fold lexically.
2. Critical CI Warning Catch for
b05bc7c(-D dead-code)In commit
b05bc7c:By inlining the folding loop into the canonical prefix loop and returning
return Ok(out);directly, the helper functionfn normalize(path: &Path) -> PathBuf(at line 107) is left with zero call sites.Because
.github/workflows/ci.ymlstrictly enforces:rustcwill reject the compilation witherror: function normalize is never used [-D dead-code].Action needed in
b05bc7c: Delete the unusedfn normalizehelper function (or gate/remove it) to keep CI green.3. macOS / POSIX Symlink Behavior
Tested on macOS (APFS):
On Darwin systems, standard temporary directories sit under
/var/folders/...(where/varis a symlink to/private/var). Component-based peeling viaexisting.components().next_back()correctly separates the existing canonicalized prefix from non-existing trailing components, avoiding the spuriousPolicyError::Iopreviously triggered byfile_name()returningNoneon trailing...AI-assisted review with Antigravity.
@pushkarreddyy on GitHub · 2026-11-24 14:12 UTC · original · edited 2026-11-24 14:22 UTC
Thanks @DaniiL35 for the keen review and catch on the dead-code lint!
I have removed the unused fn normalize helper on fix/policy-resolve-dotdot. Head commit is now 58ee9ad.
Compare: https://github.com/Marvisak/VIctory/compare/main...pushkarreddyy:VIctory:fix/policy-resolve-dotdot
The implementation resolves both POSIX and Windows \\?\ verbatim prefixes, passes all tests, and is 100% clean under cargo clippy --workspace --all-targets --locked -- -D warnings. Ready for merge by @Marvisak @mercuryVM @LAKSHYA-cmd-tech.
@pushkarreddyy on GitHub · 2026-11-24 12:11 UTC · original · edited 2026-11-24 14:22 UTC
Verified Patch Ready on Fork
The complete fix is verified and available on my fork:
b05bc7cbased onmain(ffe310e)Changes (
crates/victory-core/src/policy.rs):existing.components().next_back(), properly capturingComponent::ParentDir,Component::CurDir, andComponent::Normalwithout returningNoneon relative traversals.ParentDirand verbatimNormal("..")directly onto the canonical base without.pop(), resolving parent directories properly even under Windows\\?\verbatim prefixes.handles_trailing_dotdot_and_curdirverifying that trailing..and.resolve cleanly on non-existent paths, while correctly catching in-repo traversals.Verification:
rustfmt --edition 2024.cargo xtask policyclean).@pushkarreddyy on GitHub · 2026-11-24 14:37 UTC · original
Pull request is now open for review: #973.
@winne42 on GitHub · 2026-11-24 19:33 UTC · original · edited 2026-11-24 19:35 UTC
I tested #1163 (
8a0ac65), #973 (58ee9ad) and studiostephe's inline patch on native Linux and as Windows builds under Wine. Each branch ran its own tests plus one shared probe, with..and.passed through toresolveas written.-D warningsnormalizenever used)studiostephe's patch accepts paths inside the repo. It folds the peeled tail in reverse order, so
<repo>/missing/..becomes<parent of repo>/missingand returnsOk. The same goes for<repo>/crates/missing/../..and<tmp>/missing/../<marked clone>/cache;mainrefuses all of them withIo. Its own test misses this because the in-repo assertion only runs whencanonicalize(root) == root, andcompiled_workspace_root()(<manifest>/../..) is never canonical.#1163 and #973 leave a symlink gap (Unix only). With
<tmp>/link -> <repo>/crates,<tmp>/missing/../link/cachereturnsOk, wheremainreturnedIo. The folded tail is never canonicalized. Resolving once more after folding a..closes it: on top of #1163 that gives 0 mismatches on both platforms, and its own tests still pass:Bug 2 doesn't reproduce on Rust 1.98.1.
Path::components()parses..in a\\?\path asParentDir, notNormal(".."). So onmainthe\\?\cases fail closed withIo, like bug 1, and theNormal("..")arms in both PRs are never reached.Recommendation: #1163 plus the re-resolve above. It has the more thorough tests.
AI-assisted (Claude Code). Tests were synthetic, with no game files.
@Marvisak on GitHub · 2026-11-25 03:53 UTC · original · edited 2026-11-26 03:45 UTC
Automated triage for the maintainers.
The two original points are settled. Point 1 is fixed in
mainby #937 ("policy: resolve a..in the not-yet-existing part of a path"). Point 2 does not reproduce, becausePath::components()parses..in a\\?\path asParentDir. #973 and #1163 are closed.Still open on
main(63bcca4): incrates/victory-core/src/policy.rs,resolvekeeps a..from the missing part of the path and folds it lexically innormalizeafter the existing part was canonicalized. Components after that..may exist and may be symlinks, and they are never resolved. On Unix,<outside>/missing/../link/cacheresolves to<outside>/link/cache, soensure_outside_repopasses whenlinkpoints into a subfolder of the repository, and callers (config.rs, capture and pipeline cache paths) then create the original path through the link. Before #937 this failed closed withPolicyError::Io. Small impact: it needs a crafted path through a symlink.Patches:
triage: needs work) re-resolves the folded path after a..was collapsed. That is the approach suggested in the 2026-11-24 19:33 comment, and it is the place to continue.cachedoes not exist yet, socanonicalize(<outside>/link/cache)fails and the unresolved<outside>/link/cacheis returned as before. Its test passes because it uses a tail (link/sub) that already exists. Re-runningresolveon the folded path, which canonicalizes its longest existing prefix (<outside>/link), covers both. Pull requests are open to everyone; review on #2530 is the way to bring this in.Generated by Claude Code
@Makto94 on GitHub · 2026-11-25 14:50 UTC · original
A note on the fix merged as #937, from an independent check made while porting it.
The new arm moves a
..from the missing tail intorest, andnormalizethen folds it lexically after the existing prefix was canonicalized. Components after that..can exist and be symlinks or junctions, and they are no longer resolved. For<outside>/missing/../link_to_repo/cache,resolvereturns<outside>/link_to_repo/cache, soensure_outside_repopasses.create_dir_allon the original path then follows the link and creates the folder inside the repository. Before #937 the same path failed withPolicyError::Io, so it failed closed.canonicalize("<outside>/missing/..")fails with ENOENT, so the arm is taken. This part is from reading the code; I did not run it on Linux.canonicalizecollapsesmissing/..itself. The paths I tried with real junctions were all refused. A\\?\path with..maderesolvereturn a path without its prefix and root (C:...) withOk, althoughcreate_dir_allon it then failed with error 123.ensure_outside_repo(&dir)and then use the originaldir:config.rs,victory-gpucapture and pipeline host, and audio capture.Possible directions: return an error when an existing component follows a lexically folded
.., resolve the rest one component at a time, or have callers use the resolved path.@bajajnaman67 on GitHub · 2026-11-25 14:53 UTC · original
Stop these mails
On Wed, 25 Nov 2026, 20:22 Maledetto, @.***> wrote:
@studiostephe on GitHub · 2026-11-26 02:30 UTC · original
The folded-
..fix in #937 left one unresolved component class: what comes after the fold.Against
mainat63bcca4. This is the remaining defect the 15:47Z triage retraction names("components after that
..may exist and may be symlinks, and they are never resolved"), andits proposed fix ("canonicalize again after a
..was folded"). No open PR carries it.What is still wrong
resolvecanonicalizes the longest existing prefix, re-appends the missing tail, and folds itlexically in
normalize(ParentDir => out.pop()). When the fold climbs into thecanonicalized prefix, the result exists — and anything in it after the fold, links among
them, is never resolved:
ensure_outside_repothen walks the resolved path's ancestors for the root marker. Iflinkpoints into a subfolder of a source tree, the resolution leaves the link in theanswer, and the callers (
config.rs, GPU capture, audio capture) runcreate_dir_allon theoriginal path, which follows the link and creates the folder inside the repository.
Before #937 the same path failed with
PolicyError::Io; it now fails open. (The triageretraction describes the same path; on this machine the ancestor walk's coverage depends on
where the marker lands, which is exactly why the resolution itself should not leave a link
behind.)
The patch
crates/victory-core/src/policy.rs,resolve(): after the lexical fold, the result eitherexists (the fold climbed into the canonical prefix) or it does not (the tail is still missing).
Canonicalize it once more; on the error, keep the lexical result. Two lines of behaviour:
Verified
Mac (M1),
main63bcca4, Rust 1.98.1:a_link_after_a_folded_dotdot_is_resolvedbuilds a second source tree in a tempdir (a real one cannot link into itself), makes
link -> tree, and resolveslink/missing/../link/sub. On unpatched main it FAILS:resolvereturns<tmp>/tree/link/sub, the link still in it. With the patch it PASSES: the answer isinside the canonicalized tree.
cargo test -p victory-core --locked: 14 passed, 0 failed (13 before; +1 the new test).rustfmt --edition 2024 --checkclean;cargo clippy -p victory-core --tests --locked:no warnings.
Not covered
symlink_dirunder#[cfg(windows)]and should behave the same(a junction is resolved by
canonicalizethere as well), but this machine is macOS; theWindows path of the test is not run here.
\\?\\verbatim case Makto94 noted separately (a\\?\\path with..returned aprefix-less
C:...): not touched by this patch; it is a different arm.qwen3.8_27b running locally on an M1 Mac
shout out to Digital Debris Los Angeles