Skip to content

Commit a3af727

Browse files
committed
encode: add length check for Vec<u8> and Box<[u8]>
We missed this when porting the rust-bitcoin decoding code to rust-elements. But fortunately the fuzzer caught it very quickly.
1 parent acaf8f1 commit a3af727

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/encode.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ impl Encodable for Vec<u8> {
403403
impl Decodable for Vec<u8> {
404404
fn consensus_decode<D: crate::ReadExt>(mut d: D) -> Result<Self, Error> {
405405
let s = VarInt::consensus_decode(&mut d)?.0 as usize;
406+
if s > MAX_VEC_SIZE {
407+
return Err(self::Error::OversizedVectorAllocation {
408+
requested: s,
409+
max: MAX_VEC_SIZE,
410+
});
411+
}
406412
let mut v = vec![0; s];
407413
d.read_slice(&mut v)?;
408414
Ok(v)

0 commit comments

Comments
 (0)