Skip to content

Commit c6ae928

Browse files
Fix overflow in lightning-invoice amount_pico_btc.
1 parent 2b14cc4 commit c6ae928

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lightning-invoice/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,10 @@ impl RawBolt11Invoice {
10681068
find_all_extract!(self.known_tagged_fields(), TaggedField::PrivateRoute(ref x), x).collect()
10691069
}
10701070

1071+
/// Returns `None` if no amount is set or on overflow.
10711072
pub fn amount_pico_btc(&self) -> Option<u64> {
1072-
self.hrp.raw_amount.map(|v| {
1073-
v * self.hrp.si_prefix.as_ref().map_or(1_000_000_000_000, |si| { si.multiplier() })
1073+
self.hrp.raw_amount.and_then(|v| {
1074+
v.checked_mul(self.hrp.si_prefix.as_ref().map_or(1_000_000_000_000, |si| { si.multiplier() }))
10741075
})
10751076
}
10761077

0 commit comments

Comments
 (0)