Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuzzer fix backport to v1.53 #32511

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/ext/transport/chttp2/transport/hpack_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ class HPackParser::Parser {

template <typename Key, typename Value>
void Encode(Key, const Value& value) {
AddToSummary(Key::key(), Key::Encode(value).size());
AddToSummary(Key::key(), EncodedSizeOfKey(Key(), value));
}

private:
Expand Down
11 changes: 11 additions & 0 deletions src/core/lib/transport/metadata_batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ StaticSlice HttpSchemeMetadata::Encode(ValueType x) {
}
}

size_t EncodedSizeOfKey(HttpSchemeMetadata, HttpSchemeMetadata::ValueType x) {
switch (x) {
case HttpSchemeMetadata::kHttp:
return 4;
case HttpSchemeMetadata::kHttps:
return 5;
default:
return 0;
}
}

const char* HttpSchemeMetadata::DisplayValue(MementoType content_type) {
switch (content_type) {
case kHttp:
Expand Down
21 changes: 21 additions & 0 deletions src/core/lib/transport/metadata_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@

namespace grpc_core {

// Given a metadata key and a value, return the encoded size.
// Defaults to calling the key's Encode() method and then calculating the size
// of that, but can be overridden for specific keys if there's a better way of
// doing this.
// May return 0 if the size is unknown/unknowable.
template <typename Key>
size_t EncodedSizeOfKey(Key, const typename Key::ValueType& value) {
return Key::Encode(value).size();
}

// grpc-timeout metadata trait.
// ValueType is defined as Timestamp - an absolute timestamp (i.e. a
// deadline!), that is converted to a duration by transports before being
Expand Down Expand Up @@ -88,6 +98,10 @@ struct TeMetadata {
static const char* DisplayValue(MementoType te);
};

inline size_t EncodedSizeOfKey(TeMetadata, TeMetadata::ValueType x) {
return x == TeMetadata::kTrailers ? 8 : 0;
}

// content-type metadata trait.
struct ContentTypeMetadata {
static constexpr bool kRepeatable = false;
Expand Down Expand Up @@ -132,6 +146,8 @@ struct HttpSchemeMetadata {
static const char* DisplayValue(MementoType content_type);
};

size_t EncodedSizeOfKey(HttpSchemeMetadata, HttpSchemeMetadata::ValueType x);

// method metadata trait.
struct HttpMethodMetadata {
static constexpr bool kRepeatable = false;
Expand Down Expand Up @@ -339,6 +355,11 @@ struct GrpcLbClientStatsMetadata {
}
};

inline size_t EncodedSizeOfKey(GrpcLbClientStatsMetadata,
GrpcLbClientStatsMetadata::ValueType) {
return 0;
}

// lb-token metadata
struct LbTokenMetadata : public SimpleSliceBasedMetadata {
static constexpr bool kRepeatable = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
frames {
max_metadata_length: 58
parse: "@\002te\000@\002te\002@\000et\000;e"
}