From f8bb97b39c0a534ec5b567885e6573dcea5acd6f Mon Sep 17 00:00:00 2001 From: Teknique Date: Mon, 24 Jul 2023 21:43:14 -0700 Subject: [PATCH 1/2] Fix(?) size check in try_from for DHTSchemaSMPL --- veilid-core/src/veilid_api/types/dht/schema/smpl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/veilid-core/src/veilid_api/types/dht/schema/smpl.rs b/veilid-core/src/veilid_api/types/dht/schema/smpl.rs index 942652fe..f1079a53 100644 --- a/veilid-core/src/veilid_api/types/dht/schema/smpl.rs +++ b/veilid-core/src/veilid_api/types/dht/schema/smpl.rs @@ -96,7 +96,7 @@ impl DHTSchemaSMPL { impl TryFrom<&[u8]> for DHTSchemaSMPL { type Error = VeilidAPIError; fn try_from(b: &[u8]) -> Result { - if b.len() != Self::FIXED_SIZE { + if b.len() < 4 { apibail_generic!("invalid size"); } if &b[0..4] != &Self::FCC { From 7fa1df0474bbda78df52066f3b0b22f3a67e28e8 Mon Sep 17 00:00:00 2001 From: Teknique Date: Tue, 25 Jul 2023 08:39:15 -0700 Subject: [PATCH 2/2] Check b.len() < Self::FIXED_SIZE, not b.len() < 4 The original thinking was that if len(b) < FIXED_SIZE, then that would be picked up later by the "invalid member length" check. In that case, this only really *needs* to make sure that the check after this for "wrong fourcc" wouldn't fail. But if len(b) < FIXED_SIZE, it really is an invalid size, and should get that error message before even starting to validate its other qualities. --- veilid-core/src/veilid_api/types/dht/schema/smpl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/veilid-core/src/veilid_api/types/dht/schema/smpl.rs b/veilid-core/src/veilid_api/types/dht/schema/smpl.rs index f1079a53..572b93e8 100644 --- a/veilid-core/src/veilid_api/types/dht/schema/smpl.rs +++ b/veilid-core/src/veilid_api/types/dht/schema/smpl.rs @@ -96,7 +96,7 @@ impl DHTSchemaSMPL { impl TryFrom<&[u8]> for DHTSchemaSMPL { type Error = VeilidAPIError; fn try_from(b: &[u8]) -> Result { - if b.len() < 4 { + if b.len() < Self::FIXED_SIZE { apibail_generic!("invalid size"); } if &b[0..4] != &Self::FCC {