From a30bb1b842a8389f280f0eeb36fd5eae51bcbe4f Mon Sep 17 00:00:00 2001 From: Protobuf Team Date: Tue, 17 May 2022 10:56:24 -0700 Subject: [PATCH] Fix upb_MiniTable_Build not handling kUpb_MessageModifier_IsExtendable. PiperOrigin-RevId: 449262594 --- upb/mini_table.c | 3 +++ upb/mini_table_test.cc | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/upb/mini_table.c b/upb/mini_table.c index caaac3310b..261bc71f0c 100644 --- a/upb/mini_table.c +++ b/upb/mini_table.c @@ -747,6 +747,9 @@ static void upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, size_t len, } else if (kUpb_EncodedValue_MinModifier <= ch && ch <= kUpb_EncodedValue_MaxModifier) { ptr = upb_MtDecoder_ParseModifier(d, ptr, ch, last_field, &msg_modifiers); + if (msg_modifiers & kUpb_MessageModifier_IsExtendable) { + d->table->ext |= kUpb_ExtMode_Extendable; + } } else if (ch == kUpb_EncodedValue_End) { if (!d->table) { upb_MtDecoder_ErrorFormat(d, "Extensions cannot have oneofs."); diff --git a/upb/mini_table_test.cc b/upb/mini_table_test.cc index 5048048ccf..bb0d6d4ef5 100644 --- a/upb/mini_table_test.cc +++ b/upb/mini_table_test.cc @@ -228,3 +228,19 @@ TEST(MiniTableEnumTest, PositiveAndNegative) { EXPECT_EQ(values.contains(i), upb_MiniTable_Enum_CheckValue(table, i)) << i; } } + +TEST_P(MiniTableTest, Extendible) { + upb::Arena arena; + upb::MtDataEncoder e; + ASSERT_TRUE(e.StartMessage(kUpb_MessageModifier_IsExtendable)); + int count = 0; + for (int i = kUpb_FieldType_Double; i < kUpb_FieldType_SInt64; i++) { + ASSERT_TRUE(e.PutField(static_cast(i), i, 0)); + count++; + } + upb::Status status; + upb_MiniTable* table = upb_MiniTable_Build( + e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); + ASSERT_NE(nullptr, table); + EXPECT_EQ(kUpb_ExtMode_Extendable, table->ext & kUpb_ExtMode_Extendable); +}