txdb: Check GetKey() result when priming cursor #35784

pull 650DataNerd wants to merge 1 commits into bitcoin:master from 650DataNerd:fix-txdb-cursor-malformed-key changing 3 files +62 −5
  1. 650DataNerd commented at 12:11 PM on July 23, 2026: none

    This fixes #35172.

    CCoinsViewDB::Cursor() primed its cached key by calling GetKey() on the first database record but ignored its return value. A failed read leaves entry.key at its default-constructed value of DB_COIN, which is indistinguishable from a genuinely valid coin key, so Valid()/GetKey() on the returned cursor incorrectly report success.

    This mirrors the same class of bug already fixed in CCoinsViewDBCursor::Next() (#7890); this PR applies the identical fix to Cursor()'s priming logic.

    Added a regression test (txdb_tests.cpp) reproducing the exact failure from the issue, confirmed it fails before the fix and passes after. Ran the full unit test suite (773 test cases) with no regressions.

  2. txdb: Check GetKey() result when priming cursor
    CCoinsViewDB::Cursor() primed its cached key by calling GetKey()
    on the first database record but ignored its return value. When
    GetKey() fails to decode a malformed record, entry.key retains its
    default-constructed value of DB_COIN, which is indistinguishable
    from a genuinely valid coin key. As a result, Valid() and GetKey()
    on the returned cursor incorrectly report success for a record that
    was never actually read.
    
    This mirrors the same class of bug already fixed in
    CCoinsViewDBCursor::Next() (see #7890); this commit applies the
    identical fix to Cursor()'s priming logic.
    
    Fixes #35172
    beaded80bf
  3. DrahtBot added the label UTXO Db and Indexes on Jul 23, 2026
  4. DrahtBot commented at 12:11 PM on July 23, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35784.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • Coin{CTxOut{1, CScript{}}, 1, false} in src/test/txdb_tests.cpp

    <sup>2026-07-23 12:11:46</sup>

  5. sedited commented at 12:17 PM on July 23, 2026: contributor

    This is a duplicate of #35654 . If you are interested in the change, please consider reviewing the original pull request. Closing.

  6. sedited closed this on Jul 23, 2026

  7. 650DataNerd commented at 12:21 PM on July 23, 2026: none

    ooh yes, I see the similarity. thankyou


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-07-25 07:50 UTC

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