From: Valentine Wallace Date: Tue, 30 Apr 2024 14:05:35 +0000 (-0400) Subject: Fix overflow in lightning-invoice amount_pico_btc. X-Git-Tag: v0.0.123-rc1~1^2~6^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=c6ae9288b9e6cfba7c1e95b0f840435b561ec15d;p=rust-lightning Fix overflow in lightning-invoice amount_pico_btc. --- diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 20eaf7a82..f06eeaa17 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() })) }) }