HLE: skip junctions in the persistent-storage quota count #2990

Open
github-bot wants to merge 2 commits from github-bot/gh-2990 into main AGit
Owner

@⁠Halfect on GitHub · 2026-11-26 02:28 UTC · original
Halfect:fix/pls-used-bytes-reparse → main · +126 −11 · 2 files · 2 commits · open

Fixes VIC-BT-040 from #1249.

What

used_bytes walks the title's persistent-local-storage folder to enforce the manifest quota. It decided what to do with each entry via DirEntry::metadata(), and it recursed:

  • metadata() reports the target of a reparse point, so a directory junction is seen as a real directory and walked.
  • A junction into its own parent makes the walk loop forever — with the recursion, that is a stack overflow in an emulator thread.
  • A junction pointing anywhere else on the host makes its bytes count against the title's quota, so the quota no longer reflects the title's own folder.

The walk now uses an explicit stack and file_type() from the directory listing: links (junctions included) are skipped, real directories are descended into, and everything else contributes its length.

Testing

  • New used_bytes_skips_junctions (Windows): a junction cycle into the folder itself and one pointing outside the tree; only the real files are counted and the walk terminates.
  • cargo test --locked -p victory-hle: 153 passed.
  • cargo clippy --locked -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Limitations

Windows-only behavior change verified on Windows; the link check is cfg-free and behaves the same on other hosts (symlinks skipped there too). Not run against a real title's storage folder.

No game data. AI-assisted (Kimi).

**@⁠Halfect** on GitHub · 2026-11-26 02:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2990) `Halfect:fix/pls-used-bytes-reparse` → `main` · +126 −11 · 2 files · 2 commits · open Fixes VIC-BT-040 from #1249. ## What `used_bytes` walks the title's persistent-local-storage folder to enforce the manifest quota. It decided what to do with each entry via `DirEntry::metadata()`, and it recursed: - `metadata()` reports the **target** of a reparse point, so a directory junction is seen as a real directory and walked. - A junction into its own parent makes the walk loop forever — with the recursion, that is a stack overflow in an emulator thread. - A junction pointing anywhere else on the host makes its bytes count against the title's quota, so the quota no longer reflects the title's own folder. The walk now uses an explicit stack and `file_type()` from the directory listing: links (junctions included) are skipped, real directories are descended into, and everything else contributes its length. ## Testing - New `used_bytes_skips_junctions` (Windows): a junction cycle into the folder itself and one pointing outside the tree; only the real files are counted and the walk terminates. - `cargo test --locked -p victory-hle`: 153 passed. - `cargo clippy --locked -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. ## Limitations Windows-only behavior change verified on Windows; the link check is `cfg`-free and behaves the same on other hosts (symlinks skipped there too). Not run against a real title's storage folder. No game data. AI-assisted (Kimi).
used_bytes followed directory links (DirEntry::metadata reports the
target on junctions) and recursed without a bound: a junction into its
own parent overflows the stack, and one pointing elsewhere charges
foreign bytes to the title's quota. Walk an explicit stack instead and
skip anything whose file_type is a link. VIC-BT-040.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:19:30 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 04:58 UTC · original

Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 5a94a83 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: used_bytes_skips_junctions.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-26 04:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2990#issuecomment-7183063155) Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `5a94a83` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `used_bytes_skips_junctions`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠Halfect on GitHub · 2026-11-26 05:03 UTC · original

Thanks @⁠futurepro62 for the full-suite run on the RTX 5070 Ti — 867 passed / 0 failed on the exact head 5a94a83, with the new used_bytes_skips_junctions test passing and the skips accounted for by pre-existing main-side issues (#2571, #1835/#2317, #1744), is exactly the coverage this change needed. Nothing further from my side; ready for review.

**@⁠Halfect** on GitHub · 2026-11-26 05:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2990#issuecomment-7183134849) Thanks @⁠futurepro62 for the full-suite run on the RTX 5070 Ti — 867 passed / 0 failed on the exact head `5a94a83`, with the new `used_bytes_skips_junctions` test passing and the skips accounted for by pre-existing main-side issues (#2571, #1835/#2317, #1744), is exactly the coverage this change needed. Nothing further from my side; ready for review.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:23 UTC · original

Automated triage for the maintainers.

Needs work: needs the maintainer's decision. The change itself reads correctly: used_bytes in crates/victory-hle/src/modules/storage.rs now walks the title's storage folder with an explicit stack instead of recursion, and skips entries whose file_type() is a link. On Windows Rust reports junctions (mount-point reparse points) as symlinks there, so a junction into its own parent no longer recurses until the stack overflows, and one pointing outside isn't charged to the quota. The user-visible case is narrow (someone has to put a junction in the storage folder), but the fix is small and safe.

The reason for the maintainer's decision: the new test used_bytes_skips_junctions spawns cmd /c mklink /J to make its junctions. Other tests do start processes (the test binary itself, dxc), but none shell out to cmd. If that's not acceptable, the junction could be made through the reparse-point API with windows-sys, which the crate already uses, or the test dropped.

CI: passing; a full-suite run in this thread on an RTX 5070 Ti also passed, including the new test.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2990#issuecomment-7183444607) <!-- victory-triage v1 head=5a94a83b14c11c61699a9df483d844edf921600d verdict=needs-work at=2026-11-26T05:24:00Z --> Automated triage for the maintainers. **Needs work: needs the maintainer's decision.** The change itself reads correctly: `used_bytes` in `crates/victory-hle/src/modules/storage.rs` now walks the title's storage folder with an explicit stack instead of recursion, and skips entries whose `file_type()` is a link. On Windows Rust reports junctions (mount-point reparse points) as symlinks there, so a junction into its own parent no longer recurses until the stack overflows, and one pointing outside isn't charged to the quota. The user-visible case is narrow (someone has to put a junction in the storage folder), but the fix is small and safe. The reason for the maintainer's decision: the new test `used_bytes_skips_junctions` spawns `cmd /c mklink /J` to make its junctions. Other tests do start processes (the test binary itself, `dxc`), but none shell out to `cmd`. If that's not acceptable, the junction could be made through the reparse-point API with `windows-sys`, which the crate already uses, or the test dropped. CI: passing; a full-suite run in this thread on an RTX 5070 Ti also passed, including the new test. --- _Generated by [Claude Code](https://claude.ai/code)_
The used_bytes_skips_junctions test made its junctions by shelling out
to cmd /c mklink /J. Make them through the reparse-point API instead
(CreateFileW + FSCTL_SET_REPARSE_POINT with IO_REPARSE_TAG_MOUNT_POINT),
which the crate's windows-sys already supports; no child process, no
cmd dependency.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 02:35 UTC · original · reviewed

Verified: DirEntry::file_type() doesn't follow links, and junctions report is_symlink()==true (mount-point reparse points are name surrogates), so both the self-cycle and the escape junction are skipped — the test asserts exactly 15 bytes. The iterative walk also removes the old recursion's stack-overflow path. Right call to count only the title's real files toward its quota.

**@⁠kotekompotek** on GitHub · 2026-11-26 02:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2990#pullrequestreview-6067805460) · **reviewed** Verified: DirEntry::file_type() doesn't follow links, and junctions report is_symlink()==true (mount-point reparse points are name surrogates), so both the self-cycle and the escape junction are skipped — the test asserts exactly 15 bytes. The iterative walk also removes the old recursion's stack-overflow path. Right call to count only the title's real files toward its quota.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 02:58 UTC · original · approved these changes

Code review on 5a94a83b (static source inspection; no Windows runtime execution):

  • crates/victory-hle/src/modules/storage.rs:94-115 cleanly replaces recursion with an explicit worklist and skips symlinks/reparse points (is_symlink()) before descending, avoiding stack-depth hazards and junction loops/escapes on stable directory trees.
  • The Windows unit test at :259 covers both a self-referential junction inside the tree and an external junction target.
  • Minor non-blocking note: checking entry metadata at :102-109 before opening the queued path at :98 remains subject to a TOCTOU swap if another process replaces a directory with a junction mid-walk, which is acceptable for ordinary title persistent-storage quota accounting.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 02:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2990#pullrequestreview-6067955156) · **approved these changes** Code review on `5a94a83b` (static source inspection; no Windows runtime execution): - `crates/victory-hle/src/modules/storage.rs:94-115` cleanly replaces recursion with an explicit worklist and skips symlinks/reparse points (`is_symlink()`) before descending, avoiding stack-depth hazards and junction loops/escapes on stable directory trees. - The Windows unit test at `:259` covers both a self-referential junction inside the tree and an external junction target. - Minor non-blocking note: checking entry metadata at `:102-109` before opening the queued path at `:98` remains subject to a TOCTOU swap if another process replaces a directory with a junction mid-walk, which is acceptable for ordinary title persistent-storage quota accounting.
Author
Owner

@⁠Halfect on GitHub · 2026-11-26 11:41 UTC · original

The cmd /c mklink /J dependency is gone in 22a2af9 — the test now makes its junctions through the reparse-point API directly, so the maintainer decision the triage asked for is no longer needed either way.

  • make_junction (test-only) creates the empty directory, opens it with CreateFileW (GENERIC_WRITE, FILE_FLAG_BACKUP_SEMANTICS) and sets a mount-point reparse point with DeviceIoControl/FSCTL_SET_REPARSE_POINT (IO_REPARSE_TAG_MOUNT_POINT, substitute name as the NT path \??\<target>, plus the print name) — exactly what mklink /J produces, with no child process. The crate already depends on windows-sys; this adds the Win32_System_IO, Win32_System_Ioctl and Win32_System_SystemServices features to the existing dependency.
  • The test still asserts the quota count sees only the two real files (15 bytes) with a self-cycle junction and an outside-pointing junction present, so it retains its teeth: following either junction would loop the walk or charge the outside 100 bytes.

Validation on 22a2af9 (Windows, CPU-only):

  • cargo test --locked -p victory-hle used_bytes: used_bytes_skips_junctions passed.
  • cargo test --locked -p victory-hle: 153 passed, 0 failed.
  • cargo clippy --locked -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok. git diff --check: clean.

No game data. AI-assisted (Kimi).

**@⁠Halfect** on GitHub · 2026-11-26 11:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2990#issuecomment-7191046957) The `cmd /c mklink /J` dependency is gone in `22a2af9` — the test now makes its junctions through the reparse-point API directly, so the maintainer decision the triage asked for is no longer needed either way. - `make_junction` (test-only) creates the empty directory, opens it with `CreateFileW` (`GENERIC_WRITE`, `FILE_FLAG_BACKUP_SEMANTICS`) and sets a mount-point reparse point with `DeviceIoControl`/`FSCTL_SET_REPARSE_POINT` (`IO_REPARSE_TAG_MOUNT_POINT`, substitute name as the NT path `\??\<target>`, plus the print name) — exactly what `mklink /J` produces, with no child process. The crate already depends on `windows-sys`; this adds the `Win32_System_IO`, `Win32_System_Ioctl` and `Win32_System_SystemServices` features to the existing dependency. - The test still asserts the quota count sees only the two real files (15 bytes) with a self-cycle junction and an outside-pointing junction present, so it retains its teeth: following either junction would loop the walk or charge the outside 100 bytes. Validation on `22a2af9` (Windows, CPU-only): - `cargo test --locked -p victory-hle used_bytes`: `used_bytes_skips_junctions` passed. - `cargo test --locked -p victory-hle`: **153 passed, 0 failed**. - `cargo clippy --locked -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. `git diff --check`: clean. No game data. AI-assisted (Kimi).
This pull request can be merged automatically.
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/2990/head:github-bot/gh-2990'
git switch 'github-bot/gh-2990'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2990'
git switch 'github-bot/gh-2990'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2990'
git switch 'github-bot/gh-2990'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2990'
git switch 'main'
git merge --squash 'github-bot/gh-2990'
git switch 'main'
git merge --ff-only 'github-bot/gh-2990'
git switch 'main'
git merge 'github-bot/gh-2990'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2990
No description provided.