Fix trivial DoS when deserializing messages from the network
This commit is contained in:
parent
08c756d20e
commit
98796576d2
|
@ -659,6 +659,12 @@ impl<D: Decoder> Decodable<D> for CheckedData {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn consensus_decode(d: &mut D) -> Result<CheckedData, self::Error> {
|
fn consensus_decode(d: &mut D) -> Result<CheckedData, self::Error> {
|
||||||
let len: u32 = Decodable::consensus_decode(d)?;
|
let len: u32 = Decodable::consensus_decode(d)?;
|
||||||
|
if len > MAX_VEC_SIZE as u32 {
|
||||||
|
return Err(self::Error::OversizedVectorAllocation {
|
||||||
|
requested: len as usize,
|
||||||
|
max: MAX_VEC_SIZE
|
||||||
|
});
|
||||||
|
}
|
||||||
let checksum: [u8; 4] = Decodable::consensus_decode(d)?;
|
let checksum: [u8; 4] = Decodable::consensus_decode(d)?;
|
||||||
let mut ret = Vec::with_capacity(len as usize);
|
let mut ret = Vec::with_capacity(len as usize);
|
||||||
ret.resize(len as usize, 0);
|
ret.resize(len as usize, 0);
|
||||||
|
|
Loading…
Reference in New Issue