Fatal crash bug in validation.cpp for blocks >128MB
The Bug
bitcoind
crashes if it receives a block larger than 128MB, the MAX_BLOCKFILE_SIZE
.
This only matters on scalenet currently but this bug needs to be fixed. This also affects BU.
Steps to Reproduce
- Mine a block that is >128MB
- Watch
bitcoind
be unable to process the block and lock up, eating RAM until it is killed with an OOM.
Source of the Bug
This bit of code in validation.cpp. The loop never terminates. It spins forever. Here it is as an image to have it in-line here in the issue:
Proposed Fix
Make the loop check if vinfoBlockFile[nFile].nSize == 0
as a loop terminating condition. Or better yet, don't make it a while
loop but an if
. It only ever needs to iterate once. That's called an if
, not a while
:).
The fix would allow for a single file to exceed MAX_BLOCKFILE_SIZE
of 128MB if the file is new. Right now what happens is it doesn't even allow that -- so it keeps scanning for a new file and it dies after it runs out of memory as it allocates a bazillion instances of the block file index struct.