From f743c37e9a06872f9375c694793991024ea7b1ce Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Wed, 17 Jul 2024 12:50:36 +0200 Subject: [PATCH] Enforce a maximum key length. --- linera-execution/src/lib.rs | 5 +++++ linera-execution/src/runtime.rs | 5 +++++ linera-service-graphql-client/src/service.rs | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/linera-execution/src/lib.rs b/linera-execution/src/lib.rs index 880401b1355e..33f784283337 100644 --- a/linera-execution/src/lib.rs +++ b/linera-execution/src/lib.rs @@ -73,6 +73,9 @@ pub use crate::{ }, }; +/// The maximum length of an event key in bytes. +const MAX_EVENT_KEY_LEN: usize = 64; + /// An implementation of [`UserContractModule`]. pub type UserContractCode = Arc; @@ -165,6 +168,8 @@ pub enum ExecutionError { #[error("Blob not found on storage read: {0}")] BlobNotFoundOnRead(BlobId), + #[error("Event keys can be at most {MAX_EVENT_KEY_LEN} bytes.")] + EventKeyTooLong, } /// The public entry points provided by the contract part of an application. diff --git a/linera-execution/src/runtime.rs b/linera-execution/src/runtime.rs index c7309dabfa03..0b97e9d15650 100644 --- a/linera-execution/src/runtime.rs +++ b/linera-execution/src/runtime.rs @@ -32,6 +32,7 @@ use crate::{ BaseRuntime, ContractRuntime, ExecutionError, ExecutionOutcome, FinalizeContext, MessageContext, OperationContext, QueryContext, RawExecutionOutcome, ServiceRuntime, UserApplicationDescription, UserApplicationId, UserContractInstance, UserServiceInstance, + MAX_EVENT_KEY_LEN, }; #[cfg(test)] @@ -1266,6 +1267,10 @@ impl ContractRuntime for ContractSyncRuntimeHandle { value: Vec, ) -> Result<(), ExecutionError> { let mut this = self.inner(); + ensure!( + key.len() <= MAX_EVENT_KEY_LEN, + ExecutionError::EventKeyTooLong + ); let application = this.current_application_mut(); application.outcome.events.push((name, key, value)); Ok(()) diff --git a/linera-service-graphql-client/src/service.rs b/linera-service-graphql-client/src/service.rs index eedab6ff0f10..b412c23bd087 100644 --- a/linera-service-graphql-client/src/service.rs +++ b/linera-service-graphql-client/src/service.rs @@ -7,7 +7,7 @@ use linera_base::{ data_types::{Amount, BlockHeight, OracleResponse, Timestamp}, identifiers::{ Account, ChainDescription, ChainId, ChannelName, Destination, GenericApplicationId, Owner, - StreamId, StreamName, + StreamName, }, }; @@ -132,6 +132,7 @@ pub struct Transfer; #[cfg(not(target_arch = "wasm32"))] mod from { + use linera_base::identifiers::StreamId; use linera_chain::data_types::{ BlockExecutionOutcome, EventRecord, ExecutedBlock, HashedCertificateValue, IncomingMessage, OutgoingMessage,