From c6ae9288b9e6cfba7c1e95b0f840435b561ec15d Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Tue, 30 Apr 2024 10:05:35 -0400 Subject: [PATCH] Fix overflow in lightning-invoice amount_pico_btc. --- lightning-invoice/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 20eaf7a82d2..f06eeaa1744 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -1068,9 +1068,10 @@ impl RawBolt11Invoice { find_all_extract!(self.known_tagged_fields(), TaggedField::PrivateRoute(ref x), x).collect() } + /// Returns `None` if no amount is set or on overflow. pub fn amount_pico_btc(&self) -> Option { - self.hrp.raw_amount.map(|v| { - v * self.hrp.si_prefix.as_ref().map_or(1_000_000_000_000, |si| { si.multiplier() }) + self.hrp.raw_amount.and_then(|v| { + v.checked_mul(self.hrp.si_prefix.as_ref().map_or(1_000_000_000_000, |si| { si.multiplier() })) }) }