Skip to content

Commit 482ed49

Browse files
invoice: reproduce parsing mismatch
This is a reproduction of the issue that I found in the lightning-invoice crate. The issue is described in details in [1]. [1] #3693 Suggested-by: @erickcestari Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent d9c20be commit 482ed49

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

lightning-invoice/.DS_Store

6 KB
Binary file not shown.

lightning-invoice/src/de.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,4 +1416,32 @@ mod test {
14161416
assert!(parse_is_code_length_err(&too_long));
14171417
assert!(!parse_is_code_length_err(&too_long[..too_long.len() - 1]));
14181418
}
1419+
1420+
#[test]
1421+
fn test_raw_data_base32_roundtrip() {
1422+
use crate::ser::Base32Iterable;
1423+
use crate::RawDataPart;
1424+
use bech32::Fe32;
1425+
1426+
// These are the expected Fe32 values that should round-trip correctly
1427+
// The critical difference is in the handling of tag 5 (Features) with empty payload
1428+
let expected_values: Vec<u8> = vec![
1429+
0, 0, 4, 8, 23, 5, 0, 1, 1, 20, 16, 0, 24, 0, 1, 18, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1430+
0, 0, 0, 0, 24, 0, 1, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0,
1431+
0, 16, 0, 0, 0, 0, 0, 5, 0, 1, 0, 13, 0, 0,
1432+
];
1433+
1434+
// Convert to Fe32 for processing
1435+
let values_input: Vec<Fe32> = expected_values
1436+
.iter()
1437+
.map(|&v| <Fe32 as TryFrom<u8>>::try_from(v).expect("Value out of range"))
1438+
.collect();
1439+
1440+
// Round-trip through the parser
1441+
let raw_data = RawDataPart::from_base32(&values_input).unwrap();
1442+
let actual_output = raw_data.fe_iter().collect::<Vec<_>>();
1443+
1444+
// The test fails because the parser doesn't correctly handle empty Features field
1445+
assert_eq!(values_input, actual_output, "Failed to correctly round-trip BOLT11 data");
1446+
}
14191447
}

lightning-invoice/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ mod prelude {
7777
use crate::prelude::*;
7878

7979
/// Re-export serialization traits
80-
#[cfg(fuzzing)]
80+
#[cfg(any(fuzzing, test))]
8181
pub use crate::de::FromBase32;
82-
#[cfg(not(fuzzing))]
82+
#[cfg(not(any(fuzzing, test)))]
8383
use crate::de::FromBase32;
8484
#[cfg(fuzzing)]
8585
pub use crate::ser::Base32Iterable;

0 commit comments

Comments
 (0)