BerkeleyRODatabase::Open reads an overflow record by following next_page until it is 0. #34959 added a check that stops once more data than item_len was read, which needs every page to add data. An overflow page with hf_offset 0 adds none. If such a page names itself as next_page, the loop reads it again and again and never ends.
This PR treats an overflow page without data as corruption.
Behavior change: a file with an empty overflow page no longer opens and fails with Overflow page has no data. Before, an empty page with next_page 0 was accepted and the record came out shorter than item_len.
Measurement: regtest, RelWithDebInfo, base a527a0077a. The file has 5 pages of 4096 bytes: one key whose value is an overflow record with item_len 100, and one overflow page.
| overflow page | master | this PR |
|---|---|---|
hf_offset 0, next_page itself |
bitcoin-wallet dump at 100 % of one core, killed after 60 s |
fails at once, exit 1 |
hf_offset 100, next_page 0 |
dumped in 0.11 s | dumped as before |
With migratewallet on master the RPC does not return and one HTTP worker stays at 100 % CPU. Other RPCs still answer, but stop had not finished after 30 s.
Tests: new case in tool_wallet.py that writes both files by hand. On master it hangs (killed after 90 s). Passing locally: test_bitcoin and test_runner.py with the default list. Not run: fuzz targets, lint.
Contributed by turingpoint.