@@ -620,6 +620,8 @@ mod fuzzy_internal_msgs {
620
620
#[ derive( Clone ) ]
621
621
pub ( crate ) struct FinalOnionHopData {
622
622
pub ( crate ) payment_secret : [ u8 ; 32 ] ,
623
+ /// The total value, in msat, of the payment as received by the ultimate recipient.
624
+ /// Message serialization may panic if this value is more than 21 million Bitcoin.
623
625
pub ( crate ) total_msat : u64 ,
624
626
}
625
627
@@ -637,6 +639,8 @@ mod fuzzy_internal_msgs {
637
639
638
640
pub struct OnionHopData {
639
641
pub ( crate ) format : OnionHopDataFormat ,
642
+ /// The value, in msat, of the payment after this hop's fee is deducted.
643
+ /// Message serialization may panic if this value is more than 21 million Bitcoin.
640
644
pub ( crate ) amt_to_forward : u64 ,
641
645
pub ( crate ) outgoing_cltv_value : u32 ,
642
646
// 12 bytes of 0-padding for Legacy format
@@ -994,6 +998,10 @@ impl Readable for FinalOnionHopData {
994
998
impl Writeable for OnionHopData {
995
999
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
996
1000
w. size_hint ( 33 ) ;
1001
+ // Note that this should never be reachable if Rust-Lightning generated the message, as we
1002
+ // check values are sane long before we get here, though its possible in the future
1003
+ // user-generated messages may hit this.
1004
+ if self . amt_to_forward > MAX_VALUE_MSAT { panic ! ( "We should never be sending infinite/overflow onion payments" ) ; }
997
1005
match self . format {
998
1006
OnionHopDataFormat :: Legacy { short_channel_id } => {
999
1007
0u8 . write ( w) ?;
@@ -1011,6 +1019,7 @@ impl Writeable for OnionHopData {
1011
1019
} ,
1012
1020
OnionHopDataFormat :: FinalNode { ref payment_data } => {
1013
1021
if let & Some ( ref final_data) = payment_data {
1022
+ if final_data. total_msat > MAX_VALUE_MSAT { panic ! ( "We should never be sending infinite/overflow onion payments" ) ; }
1014
1023
encode_varint_length_prefixed_tlv ! ( w, {
1015
1024
( 2 , HighZeroBytesDroppedVarInt ( self . amt_to_forward) ) ,
1016
1025
( 4 , HighZeroBytesDroppedVarInt ( self . outgoing_cltv_value) ) ,
0 commit comments