From ea2b732139ad5d906d3951473bc3854f5e8a15ac Mon Sep 17 00:00:00 2001 From: Jordan Beauchamp Date: Tue, 21 Jul 2020 13:16:23 +1200 Subject: [PATCH 1/2] Remove extraneous bytes check on input buffer --- src/v0/mod.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/v0/mod.rs b/src/v0/mod.rs index ee446396..962f696a 100644 --- a/src/v0/mod.rs +++ b/src/v0/mod.rs @@ -215,20 +215,16 @@ impl Decode for DoughnutV0 { let mut signature = [0_u8; 64]; input.read(&mut signature)?; - if input.read_byte().is_ok() { - Err(codec::Error::from("Doughnut contains unexpected bytes")) - } else { - Ok(Self { - holder, - issuer, - expiry, - not_before, - signature_version, - payload_version, - domains, - signature: H512::from(signature), - }) - } + Ok(Self { + holder, + issuer, + expiry, + not_before, + signature_version, + payload_version, + domains, + signature: H512::from(signature), + }) } } @@ -579,6 +575,8 @@ mod test { ); } + // TODO: reconcile once https://github.com/cennznet/doughnut-rs/issues/67 is solved + #[ignore] #[test] fn decode_error_with_too_many_bytes() { let doughnut = doughnut_builder!(); From 56dae6ca22c42154f1eb758fc1ae1ee656ed61cd Mon Sep 17 00:00:00 2001 From: Jordan Beauchamp Date: Tue, 21 Jul 2020 13:30:02 +1200 Subject: [PATCH 2/2] Keep test, add note --- src/v0/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/v0/mod.rs b/src/v0/mod.rs index 962f696a..d80f98f2 100644 --- a/src/v0/mod.rs +++ b/src/v0/mod.rs @@ -575,8 +575,6 @@ mod test { ); } - // TODO: reconcile once https://github.com/cennznet/doughnut-rs/issues/67 is solved - #[ignore] #[test] fn decode_error_with_too_many_bytes() { let doughnut = doughnut_builder!(); @@ -585,10 +583,11 @@ mod test { let result = DoughnutV0::decode(&mut &encoded[..]); - assert_eq!( - result, - Err(codec::Error::from("Doughnut contains unexpected bytes")) - ); + // This used to be a decoding error. + // It may be desirable for some use cases to fail when encountering extraneous bytes + // as a security precaution. + // TODO: reconcile with https://github.com/cennznet/doughnut-rs/issues/67 + assert!(result.is_ok()); } #[test]