Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions upb/reflection/field_def.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,11 @@ static void _upb_FieldDef_CreateExt(

f->scope.extension_scope = m;
_upb_DefBuilder_Add(ctx, f->full_name, _upb_DefType_Pack(f, UPB_DEFTYPE_EXT));
if (ctx->ext_count > UINT16_MAX) {
_upb_DefBuilder_Errf(
ctx, "too many extensions in file (%d, max %d) for field %s",
ctx->ext_count, UINT16_MAX, f->full_name);
}
f->layout_index = ctx->ext_count++;

if (ctx->layout) {
Expand Down
30 changes: 30 additions & 0 deletions upb/reflection/reflection_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,5 +389,35 @@ TEST(ReflectionTest, ZeroWeakDependencyIndexWithNoDeps) {
EXPECT_THAT(std::string(status.message()), HasSubstr("out of range"));
}

TEST(ReflectionTest, TooManyExtensions) {
google::protobuf::FileDescriptorProto proto;
proto.set_name("test.proto");
proto.set_syntax("proto2");

auto* msg = proto.add_message_type();
msg->set_name("TestMessage");
auto* range = msg->add_extension_range();
range->set_start(1);
range->set_end(100000);

for (int i = 0; i <= 65536; ++i) {
auto* ext = proto.add_extension();
ext->set_name(absl::StrCat("ext_", i));
ext->set_number(i + 1);
ext->set_label(google::protobuf::FieldDescriptorProto::LABEL_OPTIONAL);
ext->set_type(google::protobuf::FieldDescriptorProto::TYPE_INT32);
ext->set_extendee("TestMessage");
}

google::protobuf::FileDescriptorSet set;
*set.add_file() = proto;
absl::StatusOr<upb::DefPool> pool = LoadDescriptorSetFromProto(set);
EXPECT_FALSE(pool.ok());
if (!pool.ok()) {
EXPECT_THAT(std::string(pool.status().message()),
HasSubstr("too many extensions"));
}
}

} // namespace
} // namespace upb_test
Loading