Merge #9693: Prevent integer overflow in ReadVarInt.
45f0961
Prevent integer overflow in ReadVarInt. (Gregory Maxwell)
Tree-SHA512: 385ea0efb6b59d44c45a49227e5f6fff236b4775544cbeb236312a3fd87fd75c226ac56f7aa1bca66b853639da75a579610074f7582f92cf2ebd4a74bc40f6f0
This commit is contained in:
commit
c5e9e428a9
1 changed files with 9 additions and 2 deletions
|
@ -336,11 +336,18 @@ I ReadVarInt(Stream& is)
|
||||||
I n = 0;
|
I n = 0;
|
||||||
while(true) {
|
while(true) {
|
||||||
unsigned char chData = ser_readdata8(is);
|
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);
|
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++;
|
n++;
|
||||||
else
|
} else {
|
||||||
return n;
|
return n;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue