wallet: Clear streams before advancing BDB cursor #36871

pull jaromil wants to merge 1 commits into bitcoin:master from jaromil:fix/bdb-cursor-stream-reset changing 3 files +23 −1
  1. jaromil commented at 2:49 PM on November 14, 2026: contributor

    This fixes a case where migratewallet can reject an old wallet as corrupt. The v2 key metadata may include an extra flag byte that Core’s metadata loader leaves unread.

    LoadRecords reuses its key and value streams between records. BerkeleyROCursor::Next() appends to those streams, so unread bytes from one record become part of the next and can cause a deserialization error.

    Clear both streams before copying the next record, matching SQLiteCursor::Next(). This keeps the existing metadata parsing and migration code.

    The regression test reads two records while leaving part of the first key and value unread, then checks that the second record replaces both outputs.

    Testing on Linux:

    • Without the fix, the regression fails both stream-content checks.
    • With the fix, test_bitcoin --run_test=db_tests passes all tests
  2. DrahtBot added the label Wallet on Nov 14, 2026
  3. DrahtBot commented at 2:49 PM on November 14, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36167 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36167.svg"></sub> (build: Enable -Wunused by fanquake)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. wallet: Clear streams before advancing BDB cursor
    LoadRecords reuses its key and value streams between cursor calls. Record
    loaders may leave optional suffix fields unread, which BerkeleyROCursor
    currently appends to the next record. This can cause valid legacy wallets
    to fail migration with a deserialization error.
    
    Clear both streams before writing the next record, matching SQLiteCursor.
    Document the cursor's replacement contract, add a BerkeleyRO regression
    that leaves part of both streams unread, and reuse unread streams in the
    SQLite prefix tests to cover the same contract.
    00bb61e694
  5. jaromil force-pushed on Nov 14, 2026
Contributors
Labels

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: 2026-11-19 19:51 UTC

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