HLE: avoid following links during storage quota scans #1505

Closed
Calvix2k wants to merge 1 commit from upstream-pr/1506 into main
Calvix2k commented 2026-11-24 18:35:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T18:35:19Z.


Summary

Fixes VIC-BT-040 from audit issue #1249.

used_bytes previously called DirEntry::metadata(), which follows directory symlinks and junctions. A link back into the tree could recurse indefinitely, and an external link could make the title's quota scan count data outside its storage directory.

The scan now uses an explicit pending-directory stack, checks entry types without following links, skips symlinks, and counts regular files. A regression test creates a nested self-referential directory link and verifies the scan terminates while still counting nested file contents.

Verification

  • cargo test -p victory-hle --lib --locked (95 passed)
  • cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings
  • rustfmt --check --edition 2024 crates/victory-hle/src/modules/storage.rs
  • cargo xtask policy --staged
  • git diff --check

Tested on Windows 10. The regression test successfully created the directory symlink in this environment; no game data was used.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6588781247 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1506). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T18:35:19Z. --- ## Summary Fixes `VIC-BT-040` from audit issue #1249. `used_bytes` previously called `DirEntry::metadata()`, which follows directory symlinks and junctions. A link back into the tree could recurse indefinitely, and an external link could make the title's quota scan count data outside its storage directory. The scan now uses an explicit pending-directory stack, checks entry types without following links, skips symlinks, and counts regular files. A regression test creates a nested self-referential directory link and verifies the scan terminates while still counting nested file contents. ## Verification - `cargo test -p victory-hle --lib --locked` (95 passed) - `cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings` - `rustfmt --check --edition 2024 crates/victory-hle/src/modules/storage.rs` - `cargo xtask policy --staged` - `git diff --check` Tested on Windows 10. The regression test successfully created the directory symlink in this environment; no game data was used.
acetonahard-code commented 2026-11-24 23:05:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by acetonahard-code on 2026-11-24T22:32:23Z.


Tested on Windows 11 with the repo toolchain, merged into current main (70564ae):

cargo test -p victory-hle passed failed ignored
main 99 0 0
main + this PR 100 0 0
  • The new test passes.
  • cargo clippy --all-targets -- -D warnings, with and without --all-features: clean.

I didn't test with game data.


Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146350673 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1506#issuecomment-7146350673). Originally posted by [acetonahard-code](https://github.com/acetonahard-code) on 2026-11-24T22:32:23Z. --- Tested on Windows 11 with the repo toolchain, merged into current `main` (70564ae): | `cargo test -p victory-hle` | passed | failed | ignored | |---|---|---|---| | `main` | 99 | 0 | 0 | | `main` + this PR | 100 | 0 | 0 | - The new test passes. - `cargo clippy --all-targets -- -D warnings`, with and without `--all-features`: clean. I didn't test with game data. --- <sub>Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.</sub>
upstream-sync closed this pull request 2026-11-25 01:06:45 +00:00
Marvisak commented 2026-11-25 01:08:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:41:50Z.


Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148781643 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1506#issuecomment-7148781643). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:41:50Z. --- Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Calvix2k commented 2026-11-25 01:08:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T00:52:08Z.


Before I rework this: could you say which case the triage considered incorrect? I see two candidates and would fix the right one rather than guess:

  • Windows junctions/mount points. FileType::is_symlink() does not necessarily catch a junction, so is_dir() would still push it and the loop follows it — the PR would not actually close the hole it targets. I can switch to symlink_metadata and skip every FILE_ATTRIBUTE_REPARSE_POINT directory instead.
  • File links. The PR also stops counting a symlinked file, which would under-count a tree that legitimately links saves. I can keep following file links (counting their target size) and only refuse directory links.

If the intended semantic is "count the title's own files, never traverse out of the storage root", I can implement exactly that with reparse-point detection and a test for a junction as well as a symlink. No reopen until that is agreed.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148972684 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1506#issuecomment-7148972684). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-25T00:52:08Z. --- Before I rework this: could you say which case the triage considered incorrect? I see two candidates and would fix the right one rather than guess: - **Windows junctions/mount points.** FileType::is_symlink() does not necessarily catch a junction, so is_dir() would still push it and the loop follows it — the PR would not actually close the hole it targets. I can switch to symlink_metadata and skip every FILE_ATTRIBUTE_REPARSE_POINT directory instead. - **File links.** The PR also stops counting a symlinked *file*, which would under-count a tree that legitimately links saves. I can keep following file links (counting their target size) and only refuse directory links. If the intended semantic is "count the title's own files, never traverse out of the storage root", I can implement exactly that with reparse-point detection and a test for a junction as well as a symlink. No reopen until that is agreed.

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