Skip to content

Commit 5d6e5c3

Browse files
committed
decode: Add empty data check
Currently we index into the data field without first checking it is not empty. For context, the indexing is done _before_ we do segwit validity checks which check for correct data lengths. This is a real noob bug , bad Tobin - no biscuit. Add a check for the empty array before indexing into it.
1 parent ea16371 commit 5d6e5c3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/primitives/decode.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ impl<'s> SegwitHrpstring<'s> {
368368
pub fn new(s: &'s str) -> Result<Self, SegwitHrpstringError> {
369369
let unchecked = UncheckedHrpstring::new(s)?;
370370

371+
if unchecked.data.is_empty() {
372+
return Err(SegwitHrpstringError::MissingWitnessVersion);
373+
}
374+
371375
// Unwrap ok since check_characters (in `Self::new`) checked the bech32-ness of this char.
372376
let witness_version = Fe32::from_char(unchecked.data[0].into()).unwrap();
373377
if witness_version.to_u8() > 16 {

0 commit comments

Comments
 (0)