Skip to content

Commit 3d8f887

Browse files
committed
Fuzz fix
1 parent 8bf6312 commit 3d8f887

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

fuzz/src/bolt11_deser.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use crate::utils::test_logger;
1111
use bech32::Fe32;
1212
use bitcoin::secp256k1::{Secp256k1, SecretKey};
1313
use lightning_invoice::{
14-
Bolt11Invoice, FromBase32, RawBolt11Invoice, RawDataPart, RawHrp, RawTaggedField, TaggedField,
14+
Base32Iterable, Bolt11Invoice, FromBase32, RawBolt11Invoice, RawDataPart, RawHrp,
15+
RawTaggedField, TaggedField,
1516
};
1617
use std::str::FromStr;
1718

@@ -31,12 +32,13 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
3132
Err(_) => return,
3233
};
3334

35+
let invoice_data_base32 = invoice_data.fe_iter().collect::<Vec<_>>();
3436
// Our data encoding is not worse than the input
35-
assert!(invoice_data.to_base32().len() <= bech32.len());
37+
assert!(invoice_data_base32.len() <= bech32.len());
3638

3739
// Our data serialization is loss-less
3840
assert_eq!(
39-
RawDataPart::from_base32(&invoice_data.to_base32())
41+
RawDataPart::from_base32(&invoice_data_base32)
4042
.expect("faild parsing out own encoding"),
4143
invoice_data
4244
);

lightning-invoice/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ mod prelude {
7777

7878
use crate::prelude::*;
7979

80+
/// Re-export serialization traits
81+
#[cfg(fuzzing)]
82+
pub use crate::ser::Base32Iterable;
83+
8084
/// Trait for paring/converting base32 slice.
8185
pub trait FromBase32: Sized {
8286
/// The associated error which can be returned from parsing (e.g. because of bad padding).

lightning-invoice/src/ser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::{Bolt11Invoice, Bolt11InvoiceFeatures, Sha256, TaggedField, ExpiryTim
1212
/// Objects that can be encoded to base32 (bech32).
1313
///
1414
/// Private to this crate to avoid polluting the API.
15-
pub(crate) trait Base32Iterable {
15+
pub trait Base32Iterable {
1616
/// apoelstra: In future we want to replace this Box<dyn Iterator> with an explicit
1717
/// associated type, to avoid the allocation. But we cannot do this until
1818
/// Rust 1.65 and GATs since the iterator may contain a reference to self.

0 commit comments

Comments
 (0)