Skip to content

Commit

Permalink
fix a deserialization overflow edge case
Browse files Browse the repository at this point in the history
A specially-constructed BlockTransactionsRequest can overflow in
deserialization in a way that is currently harmless.
  • Loading branch information
kazcw committed Nov 13, 2018
1 parent 051faf7 commit 6bed4b3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/blockencodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ class BlockTransactionsRequest {
}
}

uint16_t offset = 0;
int32_t offset = 0;
for (size_t j = 0; j < indexes.size(); j++) {
if (uint64_t(indexes[j]) + uint64_t(offset) > std::numeric_limits<uint16_t>::max())
if (int32_t(indexes[j]) + offset > std::numeric_limits<uint16_t>::max())
throw std::ios_base::failure("indexes overflowed 16 bits");
indexes[j] = indexes[j] + offset;
offset = indexes[j] + 1;
offset = int32_t(indexes[j]) + 1;
}
} else {
for (size_t i = 0; i < indexes.size(); i++) {
Expand Down

0 comments on commit 6bed4b3

Please sign in to comment.