Stop untrusted preallocation during script deserialization
This is an easy memory denial of service attack.
This commit is contained in:
parent
609d70ae53
commit
5c55f7210c
|
@ -1,11 +1,10 @@
|
||||||
|
//! Bitcoin script for Zebra
|
||||||
|
|
||||||
#![allow(clippy::unit_arg)]
|
#![allow(clippy::unit_arg)]
|
||||||
use crate::serialization::{
|
|
||||||
ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
|
use crate::serialization::{SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize};
|
||||||
};
|
|
||||||
use std::{
|
use std::{fmt, io};
|
||||||
fmt,
|
|
||||||
io::{self, Read},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// An encoding of a Bitcoin script.
|
/// An encoding of a Bitcoin script.
|
||||||
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize, Hash)]
|
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize, Hash)]
|
||||||
|
@ -32,12 +31,8 @@ impl ZcashSerialize for Script {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ZcashDeserialize for Script {
|
impl ZcashDeserialize for Script {
|
||||||
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
|
fn zcash_deserialize<R: io::Read>(reader: R) -> Result<Self, SerializationError> {
|
||||||
// XXX what is the max length of a script?
|
Ok(Script(Vec::zcash_deserialize(reader)?))
|
||||||
let len = reader.read_compactsize()?;
|
|
||||||
let mut bytes = Vec::new();
|
|
||||||
reader.take(len).read_to_end(&mut bytes)?;
|
|
||||||
Ok(Script(bytes))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue