Better handle invalid content-type (#28377)

pull/28416/head
Craig Tiller 3 years ago committed by GitHub
parent fb54d04ae2
commit 99e833d751
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/core/ext/transport/chttp2/transport/hpack_encoder.cc
  2. 13
      src/core/lib/transport/metadata_batch.h
  3. 35
      test/core/end2end/fuzzers/api_fuzzer_corpus/testcase-4902018028535808

@ -611,7 +611,10 @@ void HPackCompressor::Framer::Encode(TeMetadata, TeMetadata::ValueType value) {
void HPackCompressor::Framer::Encode(ContentTypeMetadata,
ContentTypeMetadata::ValueType value) {
GPR_ASSERT(value == ContentTypeMetadata::ValueType::kApplicationGrpc);
if (value != ContentTypeMetadata::ValueType::kApplicationGrpc) {
gpr_log(GPR_ERROR, "Not encoding bad content-type header");
return;
}
EncodeAlwaysIndexed(
&compressor_->content_type_index_, GRPC_MDSTR_CONTENT_TYPE,
StaticSlice::FromStaticString("application/grpc").c_slice(),

@ -888,12 +888,23 @@ class MetadataMap {
template <typename Which>
void Encode(Which, const typename Which::ValueType& value) {
size_ += Which::key().length() + Which::Encode(value).length() + 32;
Add(Which(), value);
}
void Encode(ContentTypeMetadata,
const typename ContentTypeMetadata::ValueType& value) {
if (value == ContentTypeMetadata::kInvalid) return;
Add(ContentTypeMetadata(), value);
}
size_t size() const { return size_; }
private:
template <typename Which>
void Add(Which, const typename Which::ValueType& value) {
size_ += Which::key().length() + Which::Encode(value).length() + 32;
}
uint32_t size_ = 0;
};

@ -0,0 +1,35 @@
actions {
create_channel {
target: "unix:"
channel_actions {
add_n_bytes_writable: 42932895744
add_n_bytes_readable: 34359738368
}
}
}
actions {
create_call {
propagation_mask: 9869440
method {
value: "v"
intern: true
}
timeout: 1000000000
}
}
actions {
queue_batch {
operations {
send_initial_metadata {
metadata {
key {
value: "content-type"
}
value {
value: "u-bin"
}
}
}
}
}
}
Loading…
Cancel
Save