From 41118e17f87561afc8cbe1f3dd528624f06906a7 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Sun, 14 Dec 2025 10:17:07 +0100 Subject: [PATCH] blockstorage: simplify partial block read validation Use `SaturatingAdd` following https://github.com/bitcoin/bitcoin/pull/33657#discussion_r2610832092. --- src/node/blockstorage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 22c8f619e60..e39b4163fc5 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -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);