mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-12-25 23:39:22 -05:00
fix lengths
This commit is contained in:
parent
448267217e
commit
827a3443b0
@ -1,6 +1,8 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::storage_manager::SignedValueData;
|
use crate::storage_manager::SignedValueData;
|
||||||
|
|
||||||
|
const MAX_VALUE_CHANGED_SUBKEYS_LEN: usize = 512;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(in crate::rpc_processor) struct RPCOperationValueChanged {
|
pub(in crate::rpc_processor) struct RPCOperationValueChanged {
|
||||||
key: TypedKey,
|
key: TypedKey,
|
||||||
@ -16,13 +18,21 @@ impl RPCOperationValueChanged {
|
|||||||
subkeys: ValueSubkeyRangeSet,
|
subkeys: ValueSubkeyRangeSet,
|
||||||
count: u32,
|
count: u32,
|
||||||
value: SignedValueData,
|
value: SignedValueData,
|
||||||
) -> Self {
|
) -> Result<Self, RPCError> {
|
||||||
Self {
|
// Needed because RangeSetBlaze uses different types here all the time
|
||||||
|
#[allow(clippy::unnecessary_cast)]
|
||||||
|
let subkeys_len = subkeys.ranges_len() as usize;
|
||||||
|
|
||||||
|
if subkeys_len > MAX_VALUE_CHANGED_SUBKEYS_LEN {
|
||||||
|
return Err(RPCError::protocol("ValueChanged subkeys length too long"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
key,
|
key,
|
||||||
subkeys,
|
subkeys,
|
||||||
count,
|
count,
|
||||||
value,
|
value,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn validate(&mut self, _validate_context: &RPCValidateContext) -> Result<(), RPCError> {
|
pub fn validate(&mut self, _validate_context: &RPCValidateContext) -> Result<(), RPCError> {
|
||||||
@ -62,6 +72,10 @@ impl RPCOperationValueChanged {
|
|||||||
let key = decode_typed_key(&k_reader)?;
|
let key = decode_typed_key(&k_reader)?;
|
||||||
|
|
||||||
let sk_reader = reader.get_subkeys().map_err(RPCError::protocol)?;
|
let sk_reader = reader.get_subkeys().map_err(RPCError::protocol)?;
|
||||||
|
if sk_reader.len() as usize > MAX_VALUE_CHANGED_SUBKEYS_LEN {
|
||||||
|
return Err(RPCError::protocol("ValueChanged subkeys length too long"));
|
||||||
|
}
|
||||||
|
|
||||||
let mut subkeys = ValueSubkeyRangeSet::new();
|
let mut subkeys = ValueSubkeyRangeSet::new();
|
||||||
for skr in sk_reader.iter() {
|
for skr in sk_reader.iter() {
|
||||||
let vskr = (skr.get_start(), skr.get_end());
|
let vskr = (skr.get_start(), skr.get_end());
|
||||||
|
@ -185,7 +185,7 @@ impl RPCOperationWatchValueQ {
|
|||||||
|
|
||||||
let mut sk_builder = builder.reborrow().init_subkeys(
|
let mut sk_builder = builder.reborrow().init_subkeys(
|
||||||
self.subkeys
|
self.subkeys
|
||||||
.len()
|
.ranges_len()
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(RPCError::map_internal("invalid subkey range list length"))?,
|
.map_err(RPCError::map_internal("invalid subkey range list length"))?,
|
||||||
);
|
);
|
||||||
|
@ -16,7 +16,7 @@ impl RPCProcessor {
|
|||||||
count: u32,
|
count: u32,
|
||||||
value: SignedValueData,
|
value: SignedValueData,
|
||||||
) -> RPCNetworkResult<()> {
|
) -> RPCNetworkResult<()> {
|
||||||
let value_changed = RPCOperationValueChanged::new(key, subkeys, count, value);
|
let value_changed = RPCOperationValueChanged::new(key, subkeys, count, value)?;
|
||||||
let statement =
|
let statement =
|
||||||
RPCStatement::new(RPCStatementDetail::ValueChanged(Box::new(value_changed)));
|
RPCStatement::new(RPCStatementDetail::ValueChanged(Box::new(value_changed)));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user