blockstorage: validate last file and parent links #36645

pull fametrano wants to merge 1 commits into bitcoin:master from fametrano:blockstorage-validate-index changing 2 files +87 −0
  1. fametrano commented at 8:02 AM on October 24, 2026: contributor

    A corrupt blocks/index can stop the node at startup. A last block file number of -1 makes it read before the start of a vector. A very large one makes it allocate and read that many file infos. A block without a parent, or with a parent at the wrong height, hits the assert in CBlockIndex::GetAncestor.

    I reject these entries on load, so init reports the usual database error and suggests -reindex. A last file without stored info is still accepted when the file before it has info, because running out of disk space while opening a new file leaves that state. The new unit tests fail on master, and the reindex, pruning and assumeutxo functional tests pass. #32427 would replace this database and derive the last file number from its entries.

    This is one of several PRs from a large audit of Bitcoin Core that I did with the help of LLM tools. The audit produced its evidence all at once, which is why the PRs arrive together. I understand each change fully and will answer review questions myself.

  2. blockstorage: validate last file and parent links
    A last block file number of -1 in blocks/index makes the node read
    before the start of a vector. A very large one makes it allocate and
    read that many file infos. A block without a parent, or with a parent at
    the wrong height, hits the assert in CBlockIndex::GetAncestor.
    
    I reject a negative number. I also reject a last file number when
    neither that file nor the one before it has stored file info. The file
    before is enough because the node can claim a new file and run out of
    disk space before writing to it. Every block above genesis must have a
    parent at the previous height. Loading then fails with an error, and the
    node asks for -reindex. Unit tests cover each case.
    93bafbdfdc
  3. DrahtBot added the label Block storage on Oct 24, 2026
  4. DrahtBot commented at 8:02 AM on October 24, 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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->


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-10-24 16:51 UTC

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