Skip to content

Commit

Permalink
Merge edd9645 into 505f125
Browse files Browse the repository at this point in the history
  • Loading branch information
asedeno authored Oct 4, 2024
2 parents 505f125 + edd9645 commit 84fea34
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 40 deletions.
2 changes: 1 addition & 1 deletion bazel/protobuf.patch
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ index e7555ee10..a93beb1c5 100644
@@ -8,3 +8,10 @@
# Copyright 2007 Google Inc. All Rights Reserved.

__version__ = '5.26.1'
__version__ = '5.28.2'
+
+
+if __name__ != '__main__':
Expand Down
18 changes: 9 additions & 9 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# This should match the schema defined in external_deps.bzl.

PROTOBUF_VERSION = "26.1"
PROTOBUF_VERSION = "28.2"

# These names of these deps *must* match the names used in `/bazel/protobuf.patch`,
# and both must match the names from the protobuf releases (see
# https://github.com/protocolbuffers/protobuf/releases).
# The names change in upcoming versions.
# The shas are calculated from the downloads on the releases page.
PROTOC_VERSIONS = dict(
linux_aarch_64 = "64a3b3b5f7dac0c8f9cf1cb85b2b1a237eb628644f6bcb0fb8f23db6e0d66181",
linux_x86_64 = "a7be2928c0454f132c599e25b79b7ad1b57663f2337d7f7e468a1d59b98ec1b0",
osx_aarch_64 = "26a29befa8891ecc48809958c909d284f2b9539a2eb47f22cadc631fe6abe8fd",
osx_x86_64 = "febd8821c3a2a23f72f4641471e0ab6486f4fb07b68111490a27a31681465b3c",
win64 = "9090d135a1159042b13b4e51b210e40cb820d85a5032a6eca5f9b3ca3bdfb539",
linux_aarch_64 = "91d8253cdc0f0f0fc51c2b69c80677996632f525ad84504bfa5b4ee38ad3e49c",
linux_x86_64 = "2febfd42b59ce93a28eb789019a470a3dd0449619bc04f84dad1333da261dec1",
osx_aarch_64 = "7bb048f52841789d9ec61983be0ce4c9e4fb3bd9a143462820ba9a3be0a03797",
osx_x86_64 = "232f07d12bf4806207a79ec2c7378301c52e6f2f7efdd21c0dd416f0bda103ec",
win64 = "4bde19271ed7cab9003570f28c6e4c4d71963eaf1211a86bf3bb25d9b895177a",
)

REPOSITORY_LOCATIONS_SPEC = dict(
Expand Down Expand Up @@ -935,11 +935,11 @@ REPOSITORY_LOCATIONS_SPEC = dict(
# test/common/json:gen_excluded_unicodes to recompute the ranges
# excluded from differential fuzzing that are populated in
# test/common/json/json_sanitizer_test_util.cc.
sha256 = "4fc5ff1b2c339fb86cd3a25f0b5311478ab081e65ad258c6789359cd84d421f8",
sha256 = "b2340aa47faf7ef10a0328190319d3f3bee1b24f426d4ce8f4253b6f27ce16db",
strip_prefix = "protobuf-{version}",
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v{version}/protobuf-{version}.tar.gz"],
use_category = ["dataplane_core", "controlplane"],
release_date = "2024-03-27",
release_date = "2024-09-18",
cpe = "cpe:2.3:a:google:protobuf:*",
license = "Protocol Buffers",
license_url = "https://github.com/protocolbuffers/protobuf/blob/v{version}/LICENSE",
Expand Down Expand Up @@ -1575,7 +1575,7 @@ def _compiled_protoc_deps(locations, versions):
sha256 = sha,
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v{version}/protoc-{version}-%s.zip" % platform.replace("_", "-", 1)],
use_category = ["dataplane_core", "controlplane"],
release_date = "2024-03-27",
release_date = "2024-09-18",
cpe = "N/A",
license = "Protocol Buffers",
license_url = "https://github.com/protocolbuffers/protobuf/blob/v{version}/LICENSE",
Expand Down
2 changes: 1 addition & 1 deletion source/common/protobuf/deterministic_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ uint64_t reflectionHashMessage(const Protobuf::Message& message, uint64_t seed)
const Protobuf::Descriptor* descriptor = message.GetDescriptor();
seed = HashUtil::xxHash64(descriptor->full_name(), seed);
if (descriptor->well_known_type() == Protobuf::Descriptor::WELLKNOWNTYPE_ANY) {
const ProtobufWkt::Any* any = Protobuf::DynamicCastToGenerated<ProtobufWkt::Any>(&message);
const ProtobufWkt::Any* any = Protobuf::DynamicCastMessage<ProtobufWkt::Any>(&message);
ASSERT(any != nullptr, "casting to any should always work for WELLKNOWNTYPE_ANY");
std::unique_ptr<Protobuf::Message> submsg = unpackAnyForReflection(*any);
if (submsg == nullptr) {
Expand Down
11 changes: 1 addition & 10 deletions source/common/protobuf/protobuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ using ::google::protobuf::BytesValue; // NOLINT(misc-unused-us
using ::google::protobuf::Descriptor; // NOLINT(misc-unused-using-decls)
using ::google::protobuf::DescriptorPool; // NOLINT(misc-unused-using-decls)
using ::google::protobuf::DescriptorPoolDatabase; // NOLINT(misc-unused-using-decls)
using ::google::protobuf::DynamicCastToGenerated; // NOLINT(misc-unused-using-decls)
using ::google::protobuf::DynamicCastMessage; // NOLINT(misc-unused-using-decls)
using ::google::protobuf::DynamicMessageFactory; // NOLINT(misc-unused-using-decls)
using ::google::protobuf::EnumValueDescriptor; // NOLINT(misc-unused-using-decls)
using ::google::protobuf::FieldDescriptor; // NOLINT(misc-unused-using-decls)
Expand All @@ -93,15 +93,6 @@ using ::google::protobuf::UInt32Value; // NOLINT(misc-unused-us

using Message = ::google::protobuf::MessageLite;

template <typename T> const T* DynamicCastToGenerated(const Message* from) {
return static_cast<const T*>(from);
}

template <typename T> T* DynamicCastToGenerated(Message* from) {
const Message* message_const = from;
return const_cast<T*>(DynamicCastToGenerated<T>(message_const));
}

using ReflectableMessage = std::unique_ptr<::google::protobuf::Message>;
using uint32 = uint32_t;
using int32 = int32_t;
Expand Down
2 changes: 1 addition & 1 deletion source/common/protobuf/visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ absl::Status traverseMessageWorker(ConstProtoVisitor& visitor, const Protobuf::M
absl::string_view target_type_url;

if (message.GetTypeName() == "google.protobuf.Any") {
auto* any_message = Protobuf::DynamicCastToGenerated<ProtobufWkt::Any>(&message);
auto* any_message = Protobuf::DynamicCastMessage<ProtobufWkt::Any>(&message);
inner_message = Helper::typeUrlToMessage(any_message->type_url());
target_type_url = any_message->type_url();
// inner_message must be valid as parsing would have already failed to load if there was an
Expand Down
2 changes: 1 addition & 1 deletion source/common/protobuf/visitor_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ std::unique_ptr<Protobuf::Message> typeUrlToMessage(absl::string_view type_url);
template <typename T>
absl::StatusOr<std::pair<std::unique_ptr<Protobuf::Message>, absl::string_view>>
convertTypedStruct(const Protobuf::Message& message) {
auto* typed_struct = Protobuf::DynamicCastToGenerated<T>(&message);
auto* typed_struct = Protobuf::DynamicCastMessage<T>(&message);
auto inner_message = typeUrlToMessage(typed_struct->type_url());
absl::string_view target_type_url = typed_struct->type_url();
// inner_message might be invalid as we did not previously check type_url during loading.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Envoy::Http::EarlyHeaderMutationPtr
Factory::createExtension(const Protobuf::Message& message,
Server::Configuration::FactoryContext& context) {
auto mptr = Envoy::Config::Utility::translateAnyToFactoryConfig(
*Envoy::Protobuf::DynamicCastToGenerated<const ProtobufWkt::Any>(&message),
*Envoy::Protobuf::DynamicCastMessage<const ProtobufWkt::Any>(&message),
context.messageValidationVisitor(), *this);
const auto& proto_config = MessageUtil::downcastAndValidate<
const envoy::extensions::http::early_header_mutation::header_mutation::v3::HeaderMutation&>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ absl::StatusOr<Envoy::Http::OriginalIPDetectionSharedPtr>
CustomHeaderIPDetectionFactory::createExtension(const Protobuf::Message& message,
Server::Configuration::FactoryContext& context) {
auto mptr = Envoy::Config::Utility::translateAnyToFactoryConfig(
*Envoy::Protobuf::DynamicCastToGenerated<const ProtobufWkt::Any>(&message),
*Envoy::Protobuf::DynamicCastMessage<const ProtobufWkt::Any>(&message),
context.messageValidationVisitor(), *this);
const auto& proto_config = MessageUtil::downcastAndValidate<
const envoy::extensions::http::original_ip_detection::custom_header::v3::CustomHeaderConfig&>(
Expand Down
6 changes: 3 additions & 3 deletions test/common/formatter/command_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TestCommandFactory::createCommandParserFromProto(const Protobuf::Message& messag
Server::Configuration::GenericFactoryContext&) {
// Cast the config message to the actual type to test that it was constructed properly.
[[maybe_unused]] const auto& config =
*Envoy::Protobuf::DynamicCastToGenerated<const ProtobufWkt::StringValue>(&message);
*Envoy::Protobuf::DynamicCastMessage<const ProtobufWkt::StringValue>(&message);
return std::make_unique<TestCommandParser>();
}

Expand Down Expand Up @@ -67,7 +67,7 @@ CommandParserPtr AdditionalCommandFactory::createCommandParserFromProto(
const Protobuf::Message& message, Server::Configuration::GenericFactoryContext&) {
// Cast the config message to the actual type to test that it was constructed properly.
[[maybe_unused]] const auto& config =
*Envoy::Protobuf::DynamicCastToGenerated<const ProtobufWkt::UInt32Value>(&message);
*Envoy::Protobuf::DynamicCastMessage<const ProtobufWkt::UInt32Value>(&message);
return std::make_unique<AdditionalCommandParser>();
}

Expand All @@ -86,7 +86,7 @@ FailCommandFactory::createCommandParserFromProto(const Protobuf::Message& messag
Server::Configuration::GenericFactoryContext&) {
// Cast the config message to the actual type to test that it was constructed properly.
[[maybe_unused]] const auto& config =
*Envoy::Protobuf::DynamicCastToGenerated<const ProtobufWkt::UInt64Value>(&message);
*Envoy::Protobuf::DynamicCastMessage<const ProtobufWkt::UInt64Value>(&message);
return nullptr;
}

Expand Down
7 changes: 3 additions & 4 deletions test/extensions/filters/http/common/fuzz/uber_per_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void addFileDescriptorsRecursively(const Protobuf::FileDescriptor& descriptor,

void addBookstoreProtoDescriptor(Protobuf::Message* message) {
envoy::extensions::filters::http::grpc_json_transcoder::v3::GrpcJsonTranscoder& config =
*Envoy::Protobuf::DynamicCastToGenerated<
*Envoy::Protobuf::DynamicCastMessage<
envoy::extensions::filters::http::grpc_json_transcoder::v3::GrpcJsonTranscoder>(message);
config.clear_services();
config.add_services("bookstore.Bookstore");
Expand Down Expand Up @@ -82,8 +82,7 @@ void UberFilterFuzzer::guideAnyProtoType(test::fuzz::HttpData* mutable_data, uin

void cleanTapConfig(Protobuf::Message* message) {
envoy::extensions::filters::http::tap::v3::Tap& config =
*Envoy::Protobuf::DynamicCastToGenerated<envoy::extensions::filters::http::tap::v3::Tap>(
message);
*Envoy::Protobuf::DynamicCastMessage<envoy::extensions::filters::http::tap::v3::Tap>(message);
if (config.common_config().config_type_case() ==
envoy::extensions::common::tap::v3::CommonExtensionConfig::ConfigTypeCase::kStaticConfig) {
auto const& output_config = config.common_config().static_config().output_config();
Expand Down Expand Up @@ -111,7 +110,7 @@ void cleanTapConfig(Protobuf::Message* message) {

void cleanFileSystemBufferConfig(Protobuf::Message* message) {
envoy::extensions::filters::http::file_system_buffer::v3::FileSystemBufferFilterConfig& config =
*Envoy::Protobuf::DynamicCastToGenerated<
*Envoy::Protobuf::DynamicCastMessage<
envoy::extensions::filters::http::file_system_buffer::v3::FileSystemBufferFilterConfig>(
message);
if (config.manager_config().thread_pool().thread_count() > kMaxAsyncFileManagerThreadCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void UberFilterFuzzer::checkInvalidInputForFuzzer(const std::string& filter_name
// HttpConnectionManager} on which we have constraints.
if (filter_name == NetworkFilterNames::get().DirectResponse) {
envoy::extensions::filters::network::direct_response::v3::Config& config =
*Envoy::Protobuf::DynamicCastToGenerated<
*Envoy::Protobuf::DynamicCastMessage<
envoy::extensions::filters::network::direct_response::v3::Config>(config_message);
if (config.response().specifier_case() ==
envoy::config::core::v3::DataSource::SpecifierCase::kFilename) {
Expand All @@ -112,7 +112,7 @@ void UberFilterFuzzer::checkInvalidInputForFuzzer(const std::string& filter_name
}
} else if (filter_name == NetworkFilterNames::get().LocalRateLimit) {
envoy::extensions::filters::network::local_ratelimit::v3::LocalRateLimit& config =
*Envoy::Protobuf::DynamicCastToGenerated<
*Envoy::Protobuf::DynamicCastMessage<
envoy::extensions::filters::network::local_ratelimit::v3::LocalRateLimit>(
config_message);
if (config.token_bucket().fill_interval().seconds() > SecondsPerDay) {
Expand All @@ -125,7 +125,7 @@ void UberFilterFuzzer::checkInvalidInputForFuzzer(const std::string& filter_name
}
} else if (filter_name == NetworkFilterNames::get().HttpConnectionManager) {
envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
config = *Envoy::Protobuf::DynamicCastToGenerated<
config = *Envoy::Protobuf::DynamicCastMessage<
envoy::extensions::filters::network::http_connection_manager::v3::
HttpConnectionManager>(config_message);
if (config.codec_type() == envoy::extensions::filters::network::http_connection_manager::v3::
Expand Down Expand Up @@ -158,7 +158,7 @@ void UberFilterFuzzer::checkInvalidInputForFuzzer(const std::string& filter_name
}
} else if (filter_name == NetworkFilterNames::get().EnvoyMobileHttpConnectionManager) {
envoy::extensions::filters::network::http_connection_manager::v3::
EnvoyMobileHttpConnectionManager& config = *Envoy::Protobuf::DynamicCastToGenerated<
EnvoyMobileHttpConnectionManager& config = *Envoy::Protobuf::DynamicCastMessage<
envoy::extensions::filters::network::http_connection_manager::v3::
EnvoyMobileHttpConnectionManager>(config_message);
if (config.config().codec_type() ==
Expand Down
2 changes: 1 addition & 1 deletion test/fuzz/mutable_visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void traverseMessageWorkerExt(ProtoVisitor& visitor, Protobuf::Message& message,
absl::string_view target_type_url;

if (message.GetDescriptor()->full_name() == "google.protobuf.Any") {
auto* any_message = Protobuf::DynamicCastToGenerated<ProtobufWkt::Any>(&message);
auto* any_message = Protobuf::DynamicCastMessage<ProtobufWkt::Any>(&message);
inner_message = Helper::typeUrlToMessage(any_message->type_url());
target_type_url = any_message->type_url();
if (inner_message) {
Expand Down
6 changes: 3 additions & 3 deletions test/fuzz/validated_input_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void ValidatedInputGenerator::handleAnyRules(
if (any_rules.has_required() && any_rules.required()) {
// Stop creating any message when a certain depth is reached
if (max_depth_ > 0 && current_depth_ > max_depth_) {
auto* any_message = Protobuf::DynamicCastToGenerated<ProtobufWkt::Any>(msg);
auto* any_message = Protobuf::DynamicCastMessage<ProtobufWkt::Any>(msg);
any_message->PackFrom(ProtobufWkt::Struct());
return;
}
Expand All @@ -178,7 +178,7 @@ void ValidatedInputGenerator::handleAnyRules(
const std::string field_name = std::string(message_path_.back());
FieldToTypeUrls::const_iterator field_to_typeurls_cand = field_to_typeurls.find(field_name);
if (field_to_typeurls_cand != any_map_cand->second.end()) {
auto* any_message = Protobuf::DynamicCastToGenerated<ProtobufWkt::Any>(msg);
auto* any_message = Protobuf::DynamicCastMessage<ProtobufWkt::Any>(msg);
inner_message = ProtobufMessage::Helper::typeUrlToMessage(any_message->type_url());
if (!inner_message || !any_message->UnpackTo(inner_message.get())) {
const TypeUrlAndFactory& randomed_typeurl = field_to_typeurls_cand->second.at(
Expand Down Expand Up @@ -415,7 +415,7 @@ void ValidatedInputGenerator::onEnterMessage(Protobuf::Message& msg,
const Protobuf::Descriptor* descriptor = msg.GetDescriptor();
message_path_.push_back(field_name);
if (descriptor->full_name() == kAny) {
auto* any_message = Protobuf::DynamicCastToGenerated<ProtobufWkt::Any>(&msg);
auto* any_message = Protobuf::DynamicCastMessage<ProtobufWkt::Any>(&msg);
std::unique_ptr<Protobuf::Message> inner_message =
ProtobufMessage::Helper::typeUrlToMessage(any_message->type_url());
if (!inner_message || !any_message->UnpackTo(inner_message.get())) {
Expand Down

0 comments on commit 84fea34

Please sign in to comment.