mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Merge #9693: Prevent integer overflow in ReadVarInt.
45f0961
Prevent integer overflow in ReadVarInt. (Gregory Maxwell)
Tree-SHA512: 385ea0efb6b59d44c45a49227e5f6fff236b4775544cbeb236312a3fd87fd75c226ac56f7aa1bca66b853639da75a579610074f7582f92cf2ebd4a74bc40f6f0
This commit is contained in:
parent
0db1328a24
commit
632956a806
@ -352,13 +352,20 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define FLATDATA(obj) REF(CFlatData((char*)&(obj), (char*)&(obj) + sizeof(obj)))
|
#define FLATDATA(obj) REF(CFlatData((char*)&(obj), (char*)&(obj) + sizeof(obj)))
|
||||||
#define FIXEDBITSET(obj, size) REF(CFixedBitSet(REF(obj), (size)))
|
#define FIXEDBITSET(obj, size) REF(CFixedBitSet(REF(obj), (size)))
|
||||||
|
Loading…
Reference in New Issue
Block a user