Skip to content

Commit

Permalink
Fix #612
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Sep 20, 2024
1 parent 2e57168 commit 23b433f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion networks/monero/wallet/src/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ impl Extra {
// `fill_buf` returns the current buffer, filled if empty, only empty if the reader is
// exhausted
while !r.fill_buf()?.is_empty() {
res.0.push(ExtraField::read(r)?);
let Ok(field) = ExtraField::read(r) else { break };
res.0.push(field);
}
Ok(res)
}
Expand Down
17 changes: 11 additions & 6 deletions networks/monero/wallet/src/tests/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
// Tests derived from
// https://github.com/monero-project/monero/blob/ac02af92867590ca80b2779a7bbeafa99ff94dcb/
// tests/unit_tests/test_tx_utils.cpp
// which is licensed
// which is licensed as follows:
#[rustfmt::skip]
/*
Copyright (c) 2014-2022, The Monero Project
Expand Down Expand Up @@ -105,13 +105,15 @@ fn padding_only_max_size() {
#[test]
fn padding_only_exceed_max_size() {
let buf: Vec<u8> = vec![0; MAX_TX_EXTRA_PADDING_COUNT + 1];
Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap_err();
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert!(extra.0.is_empty());
}

#[test]
fn invalid_padding_only() {
let buf: Vec<u8> = vec![0, 42];
Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap_err();
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert!(extra.0.is_empty());
}

#[test]
Expand All @@ -135,7 +137,8 @@ fn extra_nonce_only_wrong_size() {
let mut buf: Vec<u8> = vec![0; 20];
buf[0] = 2;
buf[1] = 255;
Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap_err();
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert!(extra.0.is_empty());
}

#[test]
Expand All @@ -155,7 +158,8 @@ fn pub_key_and_padding() {
fn pub_key_and_invalid_padding() {
let mut buf: Vec<u8> = PUB_KEY_BYTES.to_vec();
buf.extend([0, 1]);
Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap_err();
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert_eq!(extra.0, vec![ExtraField::PublicKey(pub_key())]);
}

#[test]
Expand All @@ -181,7 +185,8 @@ fn extra_mysterious_minergate_only_wrong_size() {
let mut buf: Vec<u8> = vec![0; 20];
buf[0] = 222;
buf[1] = 255;
Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap_err();
let extra = Extra::read::<&[u8]>(&mut buf.as_ref()).unwrap();
assert!(extra.0.is_empty());
}

#[test]
Expand Down

0 comments on commit 23b433f

Please sign in to comment.