mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 09:20:38 +00:00
wallet: Fix detection of symlinks on Windows #34603
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!34603
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-listwallet-recursion-detect-symlinks"
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?
This PR implements symlink detection for Windows, since GCC doesn't support symlinks on Windows. This is used by the wallet's
ListDatabasesin order to detect symlinks and avoid recursing them. It's also used in wallet path validation since that is also checking whether paths are symlinks, and we should properly detect symlinks on Windows.Under the hood, the
IsSymlinkfunction usesstd::filesystem::is_symlinkfor non-Windows systems. On Windows, it checks a file's attributes to determine if it is a reparse point. Strictly speaking, this will also catch files that aren't symlinks, such as directories that are Onedrive mounts. I think it's fine to not be recursively searching such directories.This is based on #34418 for the multiwallet test and CI changes that it enables. The last commit also removes the skipping of the symlink checks so that we are testing that the symlink handling behavior on Windows matches that on Linux and MacOS.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Do symlinks work fine with LLVM/Clang? cc @hebasto (#31507).
When building on Windows either with MSVC or clang-cl,
std::filesystem::is_symlinksuccessfully detects file and folder symbolic links, but fails to detect junctions.Since the in-code comment mentions "Windows cross compile", were you actually asking about the LLVM MinGW toolchain?
f507a31eec5219c3621b9d5551f9d04c2a409ded
Should we additionally check against a Reparse Point Tag value?
Why is this removed? It's actually kind of annoying to have files that need to be chmod'd before deletion
It isn't, the chmod testing is significantly changed. This is from #34418 and review comments about it should be left there.
I considered that, but didn't think any of the possible tag values were things that we actually want to support recursively scanning inside of.
Might it be better to just override fs::is_symlink on Windows?
Since the
IsSymlinkfucntion returnstruefor entities other than symlinks, we should probably add a clarifying comment.Is it intentional that we still check the symlink itself for a wallet?
If so, should we not do so even if IsSymlink throws?
This calls
IsSymlinktwice in some cases.I considered that, but we aren't already using
fs::is_symlinkso I don't think it would give us any benefit. Also, sinceIsSymlinkreturnstruefor more than just symlinks, I thought it wouldn't be appropriate to be override the stdlib function.Does this need to change? We already check for path_type == fs::file_type::directory
Yes
status()andsymlink_status()used below can also throw, so this is the same behavior.The docstring states that it returns true for reparse points on windows.
Hmm, good point. Removed
No longer relevant with https://github.com/bitcoin/bitcoin/pull/34603#discussion_r2824027663
llm nits:
windows -> Windows [Proper noun; "Windows" should be capitalized in documentation comment] (src/util/fs_helpers.h)
explicilty -> explicitly [Spelling error in comment] (this line)
Fixed
Forgot to undraft this.
utACK
The changes seem fine to me, but I would suggest adding a note in the description about hebasto's comment https://github.com/bitcoin/bitcoin/pull/34603#discussion_r2822782155 about why we're gating WIN32 in general.
Ping for review @hebasto.
cACK
I tested PR tip
b127cde3f4against base9c15022260on Windows 11 x64 (25H2), NTFS, with MinGW/GCC 15.2.0, MSVC 19.51.36257, and clang-cl 23.1.1 using Microsoft's STL.wallet_multiwallet.pypasses on the PR with all three compilers.I also added local junction checks. For a junction pointing to an outside wallet directory containing another wallet in a nested directory:
junction_walletandjunction_wallet\nested. The PR lists onlyjunction_wallet, confirming the fix.junction_wallet.The full multiwallet test with the local junction checks also passes on the PR with all three compilers.
Could we add this nested-wallet junction case to
wallet_multiwallet.py? It checks that the wallet at the junction remains discoverable while discovery does not descend into its subdirectories.This is how I created the junction/s for the test.
Attached the patch for the exact code: junction-regression.patch
Earlier concerns neither republished nor resolved: 1 minor finding. See the Run archive linked from the Review report for their assessments.
🟠 Minor ·
ListDatabaseslists Windows file symlinks thatGetWalletPathrejectsOn GCC-built Windows binaries, a top-level BDB file symlink remains advertised for migration although
GetWalletPathnow rejects it; no current in-tree caller or fixture was found that creates this input.Location:
src/wallet/db.cpp:34(head).🔵 Suggestion ·
GetWalletPathbroadens file rejection from symlinks to all Windows reparse pointsGetWalletPathnow excludes non-link Windows reparse-point files from legacy compatibility, although the stated rationale addresses directory traversal; practical incidence remains unconfirmed because visibility of the affected non-link tags has not been established.Location:
src/wallet/walletutil.cpp:70(head).🔵 Suggestion · Routine wallet-directory scans warn about supported symlink layouts
ListDatabasesnow generates warning-level messages for supported directory-symlink wallets during routine RPC and GUI scans, although non-recursion is their intended handling rather than a problem requiring administrator action.Location:
src/wallet/db.cpp:35(head).🔵 Suggestion ·
IsSymlinkdiscards the Windows error and unnecessarily converts the exception pathWhen
GetFileAttributesWfails,IsSymlinkreplaces the native error withinvalid_argumentand rebuilds the exception path through a locale-dependent narrow-string constructor, obscuring diagnosis.Location:
src/util/fs_helpers.cpp:357(head).Review coverage was incomplete.
Reviewed:
d8f14e32ca8e· Review report · Previous reportspermalink
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.