wallet_db: assert WalletDBUpgrader.storage is dict
What changed, and why it matters
This commit adds a safety check to Electrum's wallet database upgrade code. It ensures that when the wallet file format is being upgraded, the data being modified is a plain in-memory copy, not a live disk-backed structure. The goal is to prevent a failed or partial upgrade from accidentally being written to disk, which could corrupt the wallet file.
Treat as a hardening improvement. Review whether the assertion is sufficient and whether upgrade failures are handled gracefully (e.g., backups, rollback, user notification). No immediate emergency action is indicated by the commit alone.
Security signals we found
Defensive assertion added to prevent partial database writes
Addresses potential wallet file corruption during upgrade failures
Type safety check on storage backend used during upgrades
Evidence from the diff
The patch modifies WalletDBUpgrader.init in electrum/wallet_db.py to assert that self.data is a regular Python dict and not a StoredDict (or similar disk-backed/mapped container). The developer’s comment explains that this prevents partial upgrade changes from being committed to disk if an exception occurs during the upgrade process. This is a defensive hardening change rather than a fix for a specific reported exploit.
Changed components
electrum/wallet_db.pyWalletDBUpgrader classInspect captured patch +4 / −1
diff --git a/electrum/wallet_db.py b/electrum/wallet_db.py
index 90f44e3..36df854 100644
--- a/electrum/wallet_db.py
+++ b/electrum/wallet_db.py
@@ -117,9 +117,12 @@ for key in ['locked_in', 'fails', 'settles']:
class WalletDBUpgrader(Logger):
- def __init__(self, data):
+ def __init__(self, data: dict):
Logger.__init__(self)
self.data = data
+ # self.data must be in-memory dict (not a StoredDict or similar),
+ # so a failed, partial upgrade won't get commited to disk
+ assert type(self.data) == dict, type(self.data)
def get(self, key, default=None):
return self.data.get(key, default)
Why this scored 53/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.