wallet: Enforce BDB btree levels and overflow item sizes #34959

pull achow101 wants to merge 2 commits into bitcoin:master from achow101:bdbro-cycle-detection changing 2 files +32 −11
  1. achow101 commented at 8:51 pm on March 30, 2026: member

    Alternative to #34946

    BDB’s overflow records include the total length of the data to be read from the overflow pages. If this length is impossible (larger than max page * page size), or if the data that we are reading exceeds the stated length, then throw an exception as this is an invalid BDB file. This prevents infinite looping if an overflow page makes a circular reference.

    BDB BTrees also include the level in the tree that the page is supposed to be at. Leaf pages are always at level 1. Starting from the root page, we can validate that each child has a level one less than the parent, until we reach a leaf page with a level of 1. This also ensures that we cannot have circular internal page references.

  2. wallet, bdbro: Enforce overflow data lengths
    The total length of the data in an overflow record is being given to us.
    We should validate that the length is reasonable (fits in the total size
    of the file), and to stop reading additional data if the amount of data
    read exceeds the stated legnth. This prevents infinite looping behavior.
    ab13438d83
  3. DrahtBot added the label Wallet on Mar 30, 2026
  4. DrahtBot commented at 8:51 pm on March 30, 2026: contributor

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

    Reviews

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34946 (wallet: detect cycles in BDB page traversal during migration by instagibbs)

    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.

  5. DrahtBot added the label CI failed on Mar 30, 2026
  6. DrahtBot commented at 11:23 pm on March 30, 2026: contributor

    🚧 At least one of the CI tasks failed. Task macOS native, fuzz: https://github.com/bitcoin/bitcoin/actions/runs/23767143572/job/69249406422 LLM reason (✨ experimental): Fuzz test failure: wallet_bdb_parser crashed with std::runtime_error (“BTree Leaf page is not at level 1”), exiting with code 1.

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

  7. wallet, bdbro: Validate btree page levels
    BTree pages contain the level in the BTree that the page is supposed to
    be at. The root starts at some level between 1 and 255, leaves are
    always level 1. Internal pages must be a level that is one less than its
    parent. Validating that pages are at their expected level (except for
    the root page) enforces that no cycles can occur.
    6368100e97
  8. achow101 force-pushed on Mar 30, 2026
  9. DrahtBot removed the label CI failed on Mar 31, 2026

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-03-31 12:13 UTC

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