AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 64 Bitcoin

wallet: fix unnamed wallet migration failure

Public commit record

What the developer wrote

Authored by furszy

88/100 · Strong
wallet: fix unnamed wallet migration failure

When migrating any legacy unnamed wallet, a failed migration would
cause the cleanup logic to remove its parent directory. Since this
type of legacy wallet lives directly in the main '/wallets/' folder,
this resulted in unintentionally erasing all wallets, including the
backup file.

To be fully safe, we will no longer call `fs::remove_all`. Instead,
we only erase the individual db files we have created, leaving
everything else intact. The created wallets parent directories are
erased only if they are empty.
As part of this last change, `RestoreWallet` was modified to allow
an existing directory as the destination, since we no longer remove
the original wallet directory (we only remove the files we created
inside it). This also fixes the restore of top-level default wallets
during failures, which were failing due to the directory existence
check that always returns true for the /wallets/ directory.

This bug started after:
https://github.com/bitcoin/bitcoin/commit/f6ee59b6e2995a3916fb4f0d4cbe15ece2054494
Previously, the `fs::copy_file` call was failing for top-level wallets,
which prevented the `fs::remove_all` call from being reached.
✓ Descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a bug in Bitcoin Core's wallet migration feature. When a user tried to migrate an old-style unnamed wallet and the migration failed, the cleanup code accidentally deleted the entire /wallets/ directory, wiping out all wallets and the backup file. The fix changes the cleanup to only remove specific database files created during migration, and only remove newly created empty directories. It also adjusts wallet restore to allow restoring into an existing directory as long as no database file would be overwritten.

Recommended action

Users running versions affected by the bug should avoid migrating legacy unnamed wallets until patched, and should ensure backups are stored outside the wallets directory. Apply this patch and run the updated functional tests.

Security signals we found

01

Data-loss bug: failed migration could recursively delete the main wallets directory

02

Overly broad filesystem deletion: fs::remove_all replaced with targeted file removal

03

Backup destruction: cleanup removed the backup file alongside other wallets

04

Logic bug introduced by prior commit f6ee59b6e2995a3916fb4f0d4cbe15ece2054494

05

Fix includes regression test update in wallet_backup.py

Risk score

Why this scored 64/100

Our methodology →
Potential impact 22/30
Exploitability 8/25
Stealth signal 10/15
Affected reach 12/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.