]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Enforce that no bytes remain for TransactionU16LenLimited read
authorDuncan Dean <git@dunxen.dev>
Tue, 9 May 2023 06:37:58 +0000 (08:37 +0200)
committerDuncan Dean <git@dunxen.dev>
Tue, 9 May 2023 06:37:58 +0000 (08:37 +0200)
lightning/src/util/ser.rs

index 1570e5aeea44de753460b1bfcb8523c00b690dfc..cbdb5485e7bd984312c5a139e220835769f8f73b 100644 (file)
@@ -1384,7 +1384,12 @@ impl Readable for TransactionU16LenLimited {
        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
                let len = <u16 as Readable>::read(r)?;
                let mut tx_reader = FixedLengthReader::new(r, len as u64);
-               Ok(Self(Readable::read(&mut tx_reader)?))
+               let tx: Transaction = Readable::read(&mut tx_reader)?;
+               if tx_reader.bytes_remain() {
+                       Err(DecodeError::BadLengthDescriptor)
+               } else {
+                       Ok(Self(tx))
+               }
        }
 }