blockstorage: simplify partial block read validation
Use `SaturatingAdd` following https://github.com/bitcoin/bitcoin/pull/33657#discussion_r2610832092.
This commit is contained in:
1 parent
599effdeab
commit
41118e17f8
1 file changed
+1
-1
@@ -1083,7 +1083,7 @@ BlockManager::ReadRawBlockResult BlockManager::ReadRawBlock(const FlatFilePos& p
|
|||||||
|
|
||||||
if (block_part) {
|
if (block_part) {
|
||||||
const auto [offset, size]{*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
|
return util::Unexpected{ReadRawError::BadPartRange}; // Avoid logging - offset/size come from untrusted REST input
|
||||||
}
|
}
|
||||||
filein.seek(offset, SEEK_CUR);
|
filein.seek(offset, SEEK_CUR);
|
||||||
|
|||||||
Reference in new issue
Block a user