compression: handle compression flag but no header (#763)
Co-authored-by: Quentin Perez <[email protected]> Co-authored-by: Lucio Franco <[email protected]>
This commit is contained in:
co-authored by
Quentin Perez
Lucio Franco
parent
4054d61e14
commit
88008191fc
@@ -205,9 +205,20 @@ impl<T> Streaming<T> {
|
||||
let is_compressed = match self.buf.get_u8() {
|
||||
0 => false,
|
||||
1 => {
|
||||
if cfg!(feature = "compression") {
|
||||
true
|
||||
} else {
|
||||
#[cfg(feature = "compression")]
|
||||
{
|
||||
if self.encoding.is_some() {
|
||||
true
|
||||
} else {
|
||||
// https://grpc.github.io/grpc/core/md_doc_compression.html
|
||||
// An ill-constructed message with its Compressed-Flag bit set but lacking a grpc-encoding
|
||||
// entry different from identity in its metadata MUST fail with INTERNAL status,
|
||||
// its associated description indicating the invalid Compressed-Flag condition.
|
||||
return Err(Status::new(Code::Internal, "protocol error: received message with compressed-flag but no grpc-encoding was specified"));
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "compression"))]
|
||||
{
|
||||
return Err(Status::new(
|
||||
Code::Unimplemented,
|
||||
"Message compressed, compression support not enabled.".to_string(),
|
||||
@@ -250,6 +261,7 @@ impl<T> Streaming<T> {
|
||||
|
||||
if let Err(err) = decompress(
|
||||
self.encoding.unwrap_or_else(|| {
|
||||
// SAFETY: The check while in State::ReadHeader would already have returned Code::Internal
|
||||
unreachable!("message was compressed but `Streaming.encoding` was `None`. This is a bug in Tonic. Please file an issue")
|
||||
}),
|
||||
&mut self.buf,
|
||||
|
||||
Reference in New Issue
Block a user