Skip to content

Commit 6bed4b3

Browse files
committed
fix a deserialization overflow edge case
A specially-constructed BlockTransactionsRequest can overflow in deserialization in a way that is currently harmless.
1 parent 051faf7 commit 6bed4b3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/blockencodings.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ class BlockTransactionsRequest {
5252
}
5353
}
5454

55-
uint16_t offset = 0;
55+
int32_t offset = 0;
5656
for (size_t j = 0; j < indexes.size(); j++) {
57-
if (uint64_t(indexes[j]) + uint64_t(offset) > std::numeric_limits<uint16_t>::max())
57+
if (int32_t(indexes[j]) + offset > std::numeric_limits<uint16_t>::max())
5858
throw std::ios_base::failure("indexes overflowed 16 bits");
5959
indexes[j] = indexes[j] + offset;
60-
offset = indexes[j] + 1;
60+
offset = int32_t(indexes[j]) + 1;
6161
}
6262
} else {
6363
for (size_t i = 0; i < indexes.size(); i++) {

0 commit comments

Comments
 (0)