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 Sep 25, 2023
1 parent af0c83f commit 3a424c8
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 3a424c8

Please sign in to comment.