Skip to content

Commit

Permalink
Enforce a maximum key length.
Browse files Browse the repository at this point in the history
  • Loading branch information
afck committed Jul 17, 2024
1 parent 155f64c commit f743c37
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions linera-execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn UserContractModule + Send + Sync + 'static>;

Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions linera-execution/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -1266,6 +1267,10 @@ impl ContractRuntime for ContractSyncRuntimeHandle {
value: Vec<u8>,
) -> 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(())
Expand Down
3 changes: 2 additions & 1 deletion linera-service-graphql-client/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use linera_base::{
data_types::{Amount, BlockHeight, OracleResponse, Timestamp},
identifiers::{
Account, ChainDescription, ChainId, ChannelName, Destination, GenericApplicationId, Owner,
StreamId, StreamName,
StreamName,
},
};

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f743c37

Please sign in to comment.