HLE: harden storage and xpackage against path traversal and malformed inputs (fixes #1375) #2316

Closed
Xvania7 wants to merge 1 commit from upstream-pr/2318 into main
Xvania7 commented 2026-11-25 10:28:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T10:28:56Z.


Summary

Rebased test/hle-storage-hardening (324dc7b) cleanly onto main (940d32f) as requested in #1375.

  • crates/victory-hle/src/modules/files.rs: resolves . and .. for short title paths as well as verbatim paths so traversal cannot escape the mounted drive root.
  • crates/victory-hle/src/modules/xpackage.rs: guards estimate_download null pointers before writing *confirm = false and validates malformed/truncated package identifiers.
  • crates/victory-hle/src/modules/storage.rs & runtime.rs: storage quota checks and unit tests.

Tests

  • cargo test -p victory-hle --lib — 149 passed, 0 failed
  • cargo clippy -p victory-hle --all-targets -- -D warnings — 0 warnings
  • cargo xtask policy — 182 files ok
<!-- greyfinch-sync:Marvisak/VIctory:issue:6602401527 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2318). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T10:28:56Z. --- ## Summary Rebased `test/hle-storage-hardening` (`324dc7b`) cleanly onto `main` (`940d32f`) as requested in #1375. - `crates/victory-hle/src/modules/files.rs`: resolves `.` and `..` for short title paths as well as verbatim paths so traversal cannot escape the mounted drive root. - `crates/victory-hle/src/modules/xpackage.rs`: guards `estimate_download` null pointers before writing `*confirm = false` and validates malformed/truncated package identifiers. - `crates/victory-hle/src/modules/storage.rs` & `runtime.rs`: storage quota checks and unit tests. ## Tests - `cargo test -p victory-hle --lib` — 149 passed, 0 failed - `cargo clippy -p victory-hle --all-targets -- -D warnings` — 0 warnings - `cargo xtask policy` — 182 files ok
DenRakEiw commented 2026-11-25 11:04:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T10:44:24Z.

Review: COMMENTED


Verified against origin/main (940d32f):

  • storage (20/20) and files (8/8) tests pass, cargo clippy -p victory-hle --all-targets -- -D warnings has 0 warnings, and cargo xtask policy passes (183 files ok).
  • Parallel test race in modules::xpackage::tests: Running cargo test -p victory-hle xpackage with default parallel test threads fails:
    thread 'modules::xpackage::tests::the_installation_is_complete_and_alone' panicked at crates\victory-hle\src\modules\xpackage.rs:367:9:
    assertion `left == right` failed
      left: "00000000"
     right: "639AA8DD"
    
    Running with -- --test-threads=1 passes 4/4, confirming the new xpackage::tests race on shared global runtime state with the_installation_is_complete_and_alone. Serializing the xpackage::tests that touch global runtime state with a shared Mutex should eliminate this flake under default cargo test.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6056089267 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2318#pullrequestreview-6056089267). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T10:44:24Z. **Review:** COMMENTED --- Verified against `origin/main` (`940d32f`): - `storage` (20/20) and `files` (8/8) tests pass, `cargo clippy -p victory-hle --all-targets -- -D warnings` has 0 warnings, and `cargo xtask policy` passes (183 files ok). - **Parallel test race in `modules::xpackage::tests`:** Running `cargo test -p victory-hle xpackage` with default parallel test threads fails: ``` thread 'modules::xpackage::tests::the_installation_is_complete_and_alone' panicked at crates\victory-hle\src\modules\xpackage.rs:367:9: assertion `left == right` failed left: "00000000" right: "639AA8DD" ``` Running with `-- --test-threads=1` passes 4/4, confirming the new `xpackage::tests` race on shared global runtime state with `the_installation_is_complete_and_alone`. Serializing the `xpackage::tests` that touch global runtime state with a shared `Mutex` should eliminate this flake under default `cargo test`. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 11:04:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T10:54:05Z.

Review: COMMENTED


HLE: harden storage/xpackage against path traversal — normalize_parts resolves . and .. inside verbatim() (.. stops at root) (+468). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Security-relevant hardening; good.

<!-- greyfinch-sync:Marvisak/VIctory:review:6056243652 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2318#pullrequestreview-6056243652). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T10:54:05Z. **Review:** COMMENTED --- HLE: harden storage/xpackage against path traversal — normalize_parts resolves . and .. inside verbatim() (.. stops at root) (+468). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Security-relevant hardening; good.
Xvania7 commented 2026-11-25 11:05:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T10:55:59Z.


Thanks for catching that! Locked crate::runtime::TEST_TITLE_LOCK in the_installation_is_complete_and_alone and amended (a1f8e1d). Re-ran cargo test -p victory-hle --lib xpackage 5x under default parallel threads (4/4 each), cargo test -p victory-hle --lib (149/149), cargo clippy -p victory-hle --all-targets -- -D warnings (0 warnings), and cargo xtask policy (182 files ok).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160365611 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2318#issuecomment-7160365611). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T10:55:59Z. --- Thanks for catching that! Locked `crate::runtime::TEST_TITLE_LOCK` in `the_installation_is_complete_and_alone` and amended (a1f8e1d). Re-ran `cargo test -p victory-hle --lib xpackage` 5x under default parallel threads (4/4 each), `cargo test -p victory-hle --lib` (149/149), `cargo clippy -p victory-hle --all-targets -- -D warnings` (0 warnings), and `cargo xtask policy` (182 files ok).
Marvisak commented 2026-11-25 16:09:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:26:35Z.


Automated triage for the maintainers.

Merge candidate (worth a look). On main, files::translate resolved . and .. (stopping at the root) only for long paths, in verbatim; short paths went to the host as they were, so a title path like X:\..\file was resolved by Win32 to the parent of the mounted folder. This PR moves that resolution into normalize_parts and uses it whenever the tail has a .. part, so short paths behave like long ones. It also stops estimate_download in xpackage.rs from writing *confirm before failing on a null bytes. I checked the new branch against the existing X:name and verbatim-prefix handling and the vtable offsets the new tests call; the tests take a new TEST_TITLE_LOCK around the global title. The xpackage tests mostly pin existing behaviour and could be trimmed. Linked issue #1375 is confirmed. CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166849748 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2318#issuecomment-7166849748). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:26:35Z. --- <!-- victory-triage v1 head=a1f8e1d84b979dc6cf333f875c63b448037ceb7f verdict=merge-candidate at=2026-11-25T15:26:00Z --> Automated triage for the maintainers. **Merge candidate (worth a look).** On `main`, `files::translate` resolved `.` and `..` (stopping at the root) only for long paths, in `verbatim`; short paths went to the host as they were, so a title path like `X:\..\file` was resolved by Win32 to the parent of the mounted folder. This PR moves that resolution into `normalize_parts` and uses it whenever the tail has a `..` part, so short paths behave like long ones. It also stops `estimate_download` in `xpackage.rs` from writing `*confirm` before failing on a null `bytes`. I checked the new branch against the existing `X:name` and verbatim-prefix handling and the vtable offsets the new tests call; the tests take a new `TEST_TITLE_LOCK` around the global title. The xpackage tests mostly pin existing behaviour and could be trimmed. Linked issue #1375 is confirmed. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 23:04:15 +00:00
Marvisak commented 2026-11-25 23:05:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:08:21Z.


Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing in favour of #182 for the traversal fix (the bug is real). Here the has_traversal branch drops a trailing separator, so X:\a\..\b\ becomes <root>\b and a file opened with a trailing backslash succeeds where Windows fails, and it also rewrites \\?\-prefixed paths, which #182 deliberately leaves alone. The xpackage null guard changes behaviour only for a null out pointer, and most of the new tests pin existing behaviour.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175984758 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2318#issuecomment-7175984758). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:08:21Z. --- Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing in favour of #182 for the traversal fix (the bug is real). Here the `has_traversal` branch drops a trailing separator, so `X:\a\..\b\` becomes `<root>\b` and a file opened with a trailing backslash succeeds where Windows fails, and it also rewrites `\\?\`-prefixed paths, which #182 deliberately leaves alone. The xpackage null guard changes behaviour only for a null out pointer, and most of the new tests pin existing behaviour. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

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!2316
No description provided.