xpackage: the package-byte walk does not follow links, explicitly #581
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
hle
input
INTEL
lighting
linux-proton
memory
MULDER
needs-info
needs-logs
needs-rebase
NVIDIA
performance
post-merge
pr-diagnostics
pr-docs
pre-merge
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
relevance
high
relevance
low
relevance
medium
relevance
very-high
rendering
report
roadmap-proposal
saves
series-s
shaders
startup
status
blocked-by-rework
status
needs-test-report
status
needs-triage
status
ready-for-review
status
stale
status
superseded
status
wip
tools
ui
upstream
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
TrustNo1/Darner!581
Loading…
Reference in a new issue
No description provided.
Delete branch "qnjk/Darner:xpackage-reparse-recursion"
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?
Contributor role (optional)
What it changes
The reported problem does not reproduce on
main, and this description says so first. The finding (H-5) claimedpackage_bytesrecursed without bound through a directory reparse point. It does not: the walk recursed onDirEntry::metadata, and std'sDirEntry::metadatadoes not traverse symlinks ("This function will not traverse symlinks"). Measured on this machine with rustc 1.98.1 and an NTFS junction:e.metadata()givesis_symlink = true, is_dir = false, len = 0, whilePath::metadata/fs::metadatagivesis_dir = true. So the old walk counted a junction as zero bytes and finished at once; the hazard is real but latent — one metadata accessor away.What this change does, and why it is still worth a review: it lifts the walk out of
package_bytesintofn folder_bytes(dir: &Path) -> u64, and gives it the iterative,symlink_metadata-skipping shape thatstorage::used_bytesalready uses for the same class of hazard ("Links can escape this quota tree or point back to an ancestor",storage.rs:109-112), withsaturating_addinstead ofsum(). The skip becomes explicit rather than resting on which accessor the loop happens to use, and the extracted function is testable. The count is unchanged for every real package: a junction contributes 0 both before and after.How it was tested
f1074ca(one commit onc8258f9).cargo test --locked -p darner-hle --lib -- xpackage— 7 passed, 0 failed, including the new test.modules::xpackage::tests::folder_bytes_does_not_follow_a_link_to_an_ancestor: builds a temp folder withnested/file.binof 100 bytes and a junctionnested/loop -> root, then assertsfolder_bytes(root) == 100. Junctions are used rather thansymlink_dirbecause a directory symlink needsSeCreateSymbolicLinkPrivilege(measured here: symlinks denied,mklink /Jsucceeds); the test skips with a printed line ifcmd/mklinkcannot run.std::fs::metadata(e.path())instead ofe.metadata(), which is what the finding believed the code did): that version fails the test.cargo clippy --locked -p darner-hle --all-targets -- -D warningspasses.OnceLock, on its own thread.cargo clippy --workspace --all-targets --locked -- -D warnings: passes.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.cargo test --workspace --locked: not run to completion here; the pre-existingdarner-gputest deadlock (#224) anddarner-shaderwaterfall fixture failure (#227) make the whole-workspace run non-green on this machine.darner-hle's suite is green.Checklist
main.docs/asset-policy.md. (cargo xtask policy: 576 files ok.)Checked for overlap
crates/darner-hle/src/modules/xpackage.rs(checked against the file list of all 189 open pull requests), and no open or closed issue mentionsxpackage,package_bytesor a reparse point.`package_bytes` walked the title's folder with a recursive `size` that recurred into anything `DirEntry::metadata` reported as a directory. A junction inside the package can point at one of its own ancestors — what a hand-made `mklink /J` leaves behind when an install is moved to another drive — and a walk that followed it would count the same files for ever on a thread whose stack it would exhaust: `STATUS_STACK_OVERFLOW`, an abort rather than a panic the title could survive. `DirEntry::metadata` does not follow a link on the platforms we build for, so the old walk counted a junction as zero bytes instead of recurring; the hazard is one metadata accessor away, and `storage::used_bytes` already spells the skip out for the same reason ("Links can escape this quota tree or point back to an ancestor"). The walk is now that same iterative, link-skipping shape, and `folder_bytes` is lifted out of `package_bytes` so a real junction built under a temp directory holds it: a walk that followed the link overflows the test thread's stack, the walk as written adds nothing to the count.[pr-refactor] xpackage: the package-byte walk does not follow links, explicitlyto xpackage: the package-byte walk does not follow links, explicitlyView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.