bitcoind crash with corrupt wallet.dat #32124

issue 1440000bytes openend this issue on March 23, 2025
  1. 1440000bytes commented at 4:47 am on March 23, 2025: none
    02025-03-20T00:52:09Z Using SQLite Version 3.38.5
    12025-03-20T00:52:09Z Using wallet w1
    22025-03-20T00:52:09Z init message: Loading wallet…
    32025-03-20T00:52:09Z SQLite Error. Code: 1. Message: no such column: minversion in "INSERT INTO main VALUES(?, ?)"
    42025-03-20T00:52:09Z [w1] Releasing wallet w1..
    5terminate called after throwing an instance of 'std::runtime_error'
    6  what():  SQLiteDatabase: Failed to close database: database is locked
    

    I had observed bitcoind crash a few days back while testing it with a corrupt database. I was testing this because sqlite version was recently updated in core.

    Not sure if it is relevant to #32111. I can’t comment in that issue because @dergoegge has blocked me on GitHub.

    Feel free to ignore and close the issue if it’s unrelated.

  2. willcl-ark added the label Wallet on Mar 23, 2025
  3. maflcko commented at 8:47 am on March 24, 2025: member

    Not sure if it is relevant to #32111.

    32111 is about migrating (corrupt) bdb wallets (likely obtained from fuzzing), with exact steps to reproduce and the crash being due to Assertion m_wallet_flags == 0 failed. Whereas this issue is about loading (?) a corrupt (?) sqlite wallet, without steps to reproduce. Also, it is unclear how the two sqlite errors interact and if the second one is due to another dangling process on the system, or not.

    So my recommendation would be to add exact steps to reproduce, similar to #32111.

  4. 1440000bytes commented at 3:16 pm on March 24, 2025: none

    Steps to reproduce:

    1. Run bitcoind with bitcoind -regtest

    2. Create a new wallet which loads on startup with bitcoin-cli -regtest -named createwallet wallet_name=w1 load_on_startup=true

    3. Download sqlite binary: https://www.sqlite.org/download.html

    4. Exit bitcoind

    5. Use arbitrary SQL statements for wallet db with sqlite binary. Use the below SQL statements for the error mentioned in OP.

      0$ sqlite3 "wallet.dat file path"
      1SQLite version 3.49.1 2025-02-18 13:38:58
      2Enter ".help" for usage hints.
      3sqlite> CREATE TRIGGER test_trigger BEFORE INSERT ON main
      4  ...> BEGIN
      5  ...>     UPDATE main SET minversion = 'test' WHERE minversion = minversion;
      6  ...> END;
      7sqlite> .exit
      
    6. Restart bitcoind and see the error in logs

    Note: I have used v28.0 bitcoin core in this experiment.

  5. davidgumberg commented at 7:50 am on March 25, 2025: contributor

    This specific crash occurs after an unhandled exception is thrown in SQLiteBatch::SetupSQLStatements(), when creating a WalletBatch() during LoadWallet().

    IIUC, none of SQLiteBatch()’s users, handle errors thrown during batch creation, which seems like an issue to me.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-03-28 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me