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