Skip to content

Commit

Permalink
Merge #9693: Prevent integer overflow in ReadVarInt.
Browse files Browse the repository at this point in the history
45f0961 Prevent integer overflow in ReadVarInt. (Gregory Maxwell)

Tree-SHA512: 385ea0efb6b59d44c45a49227e5f6fff236b4775544cbeb236312a3fd87fd75c226ac56f7aa1bca66b853639da75a579610074f7582f92cf2ebd4a74bc40f6f0
  • Loading branch information
sipa committed Apr 17, 2017
2 parents f4db00f + 45f0961 commit c5e9e42
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,18 @@ I ReadVarInt(Stream& is)
I n = 0;
while(true) {
unsigned char chData = ser_readdata8(is);
if (n > (std::numeric_limits<I>::max() >> 7)) {
throw std::ios_base::failure("ReadVarInt(): size too large");
}
n = (n << 7) | (chData & 0x7F);
if (chData & 0x80)
if (chData & 0x80) {
if (n == std::numeric_limits<I>::max()) {
throw std::ios_base::failure("ReadVarInt(): size too large");
}
n++;
else
} else {
return n;
}
}
}

Expand Down

0 comments on commit c5e9e42

Please sign in to comment.