Skip to content

Commit 2344577

Browse files
authored
Merge pull request #4667 from jkczyz/2026-06-offer-quantity-check
Reject quantity of 0 for offers with bounded quantity
2 parents cf30d9f + 7620124 commit 2344577

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lightning/src/offers/invoice_request.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,6 +2221,19 @@ mod tests {
22212221
Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidQuantity),
22222222
}
22232223

2224+
match OfferBuilder::new(recipient_pubkey())
2225+
.amount_msats(1000)
2226+
.supported_quantity(Quantity::Bounded(ten))
2227+
.build()
2228+
.unwrap()
2229+
.request_invoice(&expanded_key, nonce, &secp_ctx, payment_id)
2230+
.unwrap()
2231+
.quantity(0)
2232+
{
2233+
Ok(_) => panic!("expected error"),
2234+
Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidQuantity),
2235+
}
2236+
22242237
let invoice_request = OfferBuilder::new(recipient_pubkey())
22252238
.amount_msats(1000)
22262239
.supported_quantity(Quantity::Unbounded)

lightning/src/offers/offer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ impl OfferContents {
975975

976976
fn is_valid_quantity(&self, quantity: u64) -> bool {
977977
match self.supported_quantity {
978-
Quantity::Bounded(n) => quantity <= n.get(),
978+
Quantity::Bounded(n) => quantity > 0 && quantity <= n.get(),
979979
Quantity::Unbounded => quantity > 0,
980980
Quantity::One => quantity == 1,
981981
}

0 commit comments

Comments
 (0)