Skip to content

Commit 7620124

Browse files
jkczyzclaude
andcommitted
Reject quantity of 0 for offers with bounded quantity
An offer advertising Quantity::Bounded expects at least one item, but is_valid_quantity accepted a quantity of 0 since it only checked the upper bound. Require the quantity to be greater than 0 so that an invoice request for 0 items is rejected as an InvalidQuantity. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0c37f08 commit 7620124

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)