Skip to content

Commit 295e05a

Browse files
committed
tlv value length check
1 parent 2f9efe6 commit 295e05a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/payment/spontaneous.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,16 @@ impl SpontaneousPayment {
119119
};
120120

121121
let recipient_fields = match custom_tlv {
122-
Some((tlv_type, tlv_value)) => RecipientOnionFields::spontaneous_empty()
123-
.with_custom_tlvs(vec![(tlv_type, tlv_value)])
124-
.map_err(|_| Error::PaymentSendingFailed)?,
122+
Some((tlv_type, tlv_value)) => {
123+
if tlv_value.len() > 1300 {
124+
// The real limit is lower, but we can't know without the full route.
125+
// This is just an early check to avoid trying a payment that will fail.
126+
return Err(Error::PaymentSendingFailed);
127+
}
128+
RecipientOnionFields::spontaneous_empty()
129+
.with_custom_tlvs(vec![(tlv_type, tlv_value)])
130+
.map_err(|_| Error::PaymentSendingFailed)?
131+
},
125132
None => RecipientOnionFields::spontaneous_empty(),
126133
};
127134

0 commit comments

Comments
 (0)