blockstorage: simplify partial block read validation

Use `SaturatingAdd` following https://github.com/bitcoin/bitcoin/pull/33657#discussion_r2610832092.
This commit is contained in:
Roman Zeyde
2025-12-14 10:17:07 +01:00
parent 599effdeab
commit 41118e17f8

View File

@@ -1083,7 +1083,7 @@ BlockManager::ReadRawBlockResult BlockManager::ReadRawBlock(const FlatFilePos& p
if (block_part) {
const auto [offset, size]{*block_part};
if (size == 0 || offset >= blk_size || size > blk_size - offset) {
if (size == 0 || SaturatingAdd(offset, size) > blk_size) {
return util::Unexpected{ReadRawError::BadPartRange}; // Avoid logging - offset/size come from untrusted REST input
}
filein.seek(offset, SEEK_CUR);