Skip to content

Commit

Permalink
feat(tonic): Add limitation on body length
Browse files Browse the repository at this point in the history
  • Loading branch information
poliorcetics committed Jul 24, 2023
1 parent c51c8b4 commit 3a343be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion tonic/src/codec/decode.rs
Expand Up @@ -187,7 +187,12 @@ impl StreamingInner {
));
}

self.buf.reserve(len);
if let Err(err) = self.buf.try_reserve(len) {
return Err(Status::internal(format!(
"Could not allocate buffer (needed size: {}): {}",
len, err
)));
}

self.state = State::ReadBody {
compression: compression_encoding,
Expand Down
2 changes: 1 addition & 1 deletion tonic/src/codec/mod.rs
Expand Up @@ -30,7 +30,7 @@ const HEADER_SIZE: usize =
std::mem::size_of::<u32>();

// The default maximum uncompressed size in bytes for a message. Defaults to 4MB.
const DEFAULT_MAX_RECV_MESSAGE_SIZE: usize = 4 * 1024 * 1024;
const DEFAULT_MAX_RECV_MESSAGE_SIZE: usize = 100 * 1024 * 1024;
const DEFAULT_MAX_SEND_MESSAGE_SIZE: usize = usize::MAX;

/// Trait that knows how to encode and decode gRPC messages.
Expand Down

0 comments on commit 3a343be

Please sign in to comment.