<!-- Pull requests without a rationale and clear improvement may be closed immediately. -->
This makes BlockManager::ReadBlock() fail if a stored block record contains trailing bytes after a complete serialized block.
Previously, ReadBlock() deserialized from the byte span returned by ReadRawBlock() but did not check whether the SpanReader consumed all bytes. If the stored record length was larger than the serialized block, the extra bytes were ignored and the block could still be returned as valid.
The change keeps the existing deserialization path, then checks that the reader is empty after reading the block.
The unit test writes the mainnet genesis block to a block file, updates the record length to include 8 extra bytes, confirms ReadRawBlock() sees the larger record, and checks that ReadBlock() rejects it.
Tested with:
cmake -S /private/tmp/bitcoin-core-block-trailing-junk-pr -B /private/tmp/bitcoin-core-block-trailing-junk-pr-build -DBUILD_TESTS=ON -DBUILD_BENCH=OFF -DBUILD_GUI=OFF -DENABLE_WALLET=ON -DBUILD_WALLET_TOOL=OFF -DENABLE_IPC=OFF -DWITH_ZMQ=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build /private/tmp/bitcoin-core-block-trailing-junk-pr-build --target test_bitcoin -j"$(sysctl -n hw.ncpu)"
/private/tmp/bitcoin-core-block-trailing-junk-pr-build/bin/test_bitcoin --run_test=blockmanager_tests