Skip to content

Commit

Permalink
Limit stream name length.
Browse files Browse the repository at this point in the history
  • Loading branch information
afck committed Jul 17, 2024
1 parent 20f6ada commit fd109a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions linera-execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub use crate::{

/// The maximum length of an event key in bytes.
const MAX_EVENT_KEY_LEN: usize = 64;
/// The maximum length of a stream name.
const MAX_STREAM_NAME_LEN: usize = 64;

/// An implementation of [`UserContractModule`].
pub type UserContractCode = Arc<dyn UserContractModule + Send + Sync + 'static>;
Expand Down Expand Up @@ -170,6 +172,8 @@ pub enum ExecutionError {
BlobNotFoundOnRead(BlobId),
#[error("Event keys can be at most {MAX_EVENT_KEY_LEN} bytes.")]
EventKeyTooLong,
#[error("Stream names can be at most {MAX_STREAM_NAME_LEN} bytes.")]
StreamNameTooLong,
}

/// The public entry points provided by the contract part of an application.
Expand Down
6 changes: 5 additions & 1 deletion linera-execution/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::{
BaseRuntime, ContractRuntime, ExecutionError, ExecutionOutcome, FinalizeContext,
MessageContext, OperationContext, QueryContext, RawExecutionOutcome, ServiceRuntime,
UserApplicationDescription, UserApplicationId, UserContractInstance, UserServiceInstance,
MAX_EVENT_KEY_LEN,
MAX_EVENT_KEY_LEN, MAX_STREAM_NAME_LEN,
};

#[cfg(test)]
Expand Down Expand Up @@ -1271,6 +1271,10 @@ impl ContractRuntime for ContractSyncRuntimeHandle {
key.len() <= MAX_EVENT_KEY_LEN,
ExecutionError::EventKeyTooLong
);
ensure!(
name.0.len() <= MAX_STREAM_NAME_LEN,
ExecutionError::StreamNameTooLong
);
let application = this.current_application_mut();
application.outcome.events.push((name, key, value));
Ok(())
Expand Down

0 comments on commit fd109a2

Please sign in to comment.