Skip to content

Commit 5d1a197

Browse files
committed
Fuzz fetching InvoiceRequestFields from VerifiedInvoiceRequests
This should allow us to reach the panic from two commits ago from the fuzzer.
1 parent eb7f6d9 commit 5d1a197

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

fuzz/src/invoice_request_deser.rs

+6
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
134134
)
135135
.unwrap();
136136

137+
if let Ok(verified) = invoice_request.clone().verify_using_metadata(&expanded_key, secp_ctx) {
138+
// Previously we had a panic where we'd truncate the payer note possibly cutting a Unicode
139+
// character in two here, so try to fetch fields if we can validate.
140+
let _ = verified.fields();
141+
}
142+
137143
let payment_hash = PaymentHash([42; 32]);
138144
invoice_request.respond_with(vec![payment_path], payment_hash)?.build()
139145
}

lightning/src/offers/invoice_request.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,14 @@ impl VerifiedInvoiceRequest {
989989
InvoiceWithDerivedSigningPubkeyBuilder
990990
);
991991

992-
pub(crate) fn fields(&self) -> InvoiceRequestFields {
992+
/// Fetch the [`InvoiceRequestFields`] for this verified invoice.
993+
///
994+
/// These are fields which we expect to be useful when receiving a payment for this invoice
995+
/// request, and include the returned [`InvoiceRequestFields`] in the
996+
/// [`PaymentContext::Bolt12Offer`].
997+
///
998+
/// [`PaymentContext::Bolt12Offer`]: crate::blinded_path::payment::PaymentContext::Bolt12Offer
999+
pub fn fields(&self) -> InvoiceRequestFields {
9931000
let InvoiceRequestContents {
9941001
payer_signing_pubkey,
9951002
inner: InvoiceRequestContentsWithoutPayerSigningPubkey { quantity, payer_note, .. },
@@ -1404,8 +1411,13 @@ pub struct InvoiceRequestFields {
14041411
}
14051412

14061413
/// The maximum number of characters included in [`InvoiceRequestFields::payer_note_truncated`].
1414+
#[cfg(not(fuzzing))]
14071415
pub const PAYER_NOTE_LIMIT: usize = 512;
14081416

1417+
/// The maximum number of characters included in [`InvoiceRequestFields::payer_note_truncated`].
1418+
#[cfg(fuzzing)]
1419+
pub const PAYER_NOTE_LIMIT: usize = 8;
1420+
14091421
impl Writeable for InvoiceRequestFields {
14101422
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
14111423
write_tlv_fields!(writer, {

0 commit comments

Comments
 (0)