diff --git a/VERSION b/VERSION index 8a9ffadf..4f024685 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -260209.1 +260810.0 diff --git a/crates/db/src/server.rs b/crates/db/src/server.rs index 7d61308e..eae1f0ef 100644 --- a/crates/db/src/server.rs +++ b/crates/db/src/server.rs @@ -26,6 +26,8 @@ use { }, }; +const MAX_HSCAN_COUNT: u32 = 5000; + struct Inner { storage: Storage, } @@ -169,6 +171,10 @@ impl StorageApi for Server { .map(|card| Output::Cardinality(card as u64)), operation::Owned::HScan(op) => { + if op.count > MAX_HSCAN_COUNT { + return Err(Error::invalid_argument()); + } + let opts = ScanOptions::new(op.count as usize).with_cursor(op.cursor); self.map_storage() diff --git a/crates/storage_api/src/lib.rs b/crates/storage_api/src/lib.rs index 4dc61733..5eec9f2b 100644 --- a/crates/storage_api/src/lib.rs +++ b/crates/storage_api/src/lib.rs @@ -434,6 +434,9 @@ pub enum ErrorKind { /// Internal error. Internal, + /// Invalid argument. + InvalidArgument, + /// Transport error. Transport, @@ -465,6 +468,11 @@ impl Error { Self::new(ErrorKind::Internal) } + /// Creates a new [`Error`] with [`ErrorKind::InvalidArgument`]. + pub const fn invalid_argument() -> Self { + Self::new(ErrorKind::InvalidArgument) + } + pub fn with_message(mut self, message: impl ToString) -> Self { self.message = Some(message.to_string()); self @@ -478,7 +486,7 @@ impl Error { /// Indicates whether this [`Error`] is transient and can be retried. pub fn is_transient(&self) -> bool { match self.kind { - ErrorKind::Unauthorized | ErrorKind::Unknown => false, + ErrorKind::Unauthorized | ErrorKind::InvalidArgument | ErrorKind::Unknown => false, ErrorKind::KeyspaceVersionMismatch | ErrorKind::Timeout | ErrorKind::Internal diff --git a/crates/storage_api/src/rpc/mod.rs b/crates/storage_api/src/rpc/mod.rs index 81c0058c..8eb17047 100644 --- a/crates/storage_api/src/rpc/mod.rs +++ b/crates/storage_api/src/rpc/mod.rs @@ -282,6 +282,7 @@ enum ErrorCode { Internal = 0, Unauthorized = 1, KeyspaceVersionMismatch = 2, + InvalidArgument = 3, } type Result = std::result::Result; @@ -299,6 +300,7 @@ impl From for crate::Error { ErrorCode::Unauthorized => ErrorKind::Unauthorized, ErrorCode::KeyspaceVersionMismatch => ErrorKind::KeyspaceVersionMismatch, ErrorCode::Internal => ErrorKind::Internal, + ErrorCode::InvalidArgument => ErrorKind::InvalidArgument, }; Self { @@ -315,6 +317,7 @@ impl From for ErrorCode { match kind { ErrorKind::Unauthorized => ErrorCode::Unauthorized, ErrorKind::KeyspaceVersionMismatch => ErrorCode::KeyspaceVersionMismatch, + ErrorKind::InvalidArgument => ErrorCode::InvalidArgument, ErrorKind::Internal | ErrorKind::Timeout