File tree Expand file tree Collapse file tree
ruby/ext/google/protobuf_c Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7145,13 +7145,26 @@ bool upb_MiniTable_SetSubMessage(upb_MiniTable* table,
71457145 UPB_ASSERT((uintptr_t)table->fields <= (uintptr_t)field &&
71467146 (uintptr_t)field <
71477147 (uintptr_t)(table->fields + table->field_count));
7148- // TODO: check these type invariants at runtime and return error to the
7149- // caller if they are violated, instead of using an assert.
7150- UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message ||
7151- field->descriptortype == kUpb_FieldType_Group);
7152- if (sub->ext & kUpb_ExtMode_IsMapEntry) {
7153- UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message);
7154- field->mode = (field->mode & ~kUpb_FieldMode_Mask) | kUpb_FieldMode_Map;
7148+ UPB_ASSERT(sub);
7149+
7150+ const bool sub_is_map = sub->ext & kUpb_ExtMode_IsMapEntry;
7151+
7152+ switch (field->descriptortype) {
7153+ case kUpb_FieldType_Message:
7154+ if (sub_is_map) {
7155+ const bool table_is_map = table->ext & kUpb_ExtMode_IsMapEntry;
7156+ if (UPB_UNLIKELY(table_is_map)) return false;
7157+
7158+ field->mode = (field->mode & ~kUpb_FieldMode_Mask) | kUpb_FieldMode_Map;
7159+ }
7160+ break;
7161+
7162+ case kUpb_FieldType_Group:
7163+ if (UPB_UNLIKELY(sub_is_map)) return false;
7164+ break;
7165+
7166+ default:
7167+ return false;
71557168 }
71567169
71577170 upb_MiniTableSub* table_sub = (void*)&table->subs[field->submsg_index];
Original file line number Diff line number Diff line change @@ -149,7 +149,7 @@ def protobuf_deps():
149149 _github_archive (
150150 name = "upb" ,
151151 repo = "https://github.com/protocolbuffers/upb" ,
152- commit = "4bea50c834fd714238c700bedecfd4b75bc833f3 " ,
153- sha256 = "5664903676dd9b784250e0a6502f712057100e362d4bbdbc0ba3ab1f3cdb7daf " ,
152+ commit = "662497f1d3dcced2bba1620cea9aae8b484bd3cd " ,
153+ sha256 = "57c87ca4145d2cbc162a6c613b114b9325b577f4f6525bd78747a34b3d03627c " ,
154154 patches = ["@com_google_protobuf//build_defs:upb.patch" ],
155155 )
Original file line number Diff line number Diff line change @@ -6782,13 +6782,26 @@ bool upb_MiniTable_SetSubMessage(upb_MiniTable* table,
67826782 UPB_ASSERT ((uintptr_t )table -> fields <= (uintptr_t )field &&
67836783 (uintptr_t )field <
67846784 (uintptr_t )(table -> fields + table -> field_count ));
6785- // TODO: check these type invariants at runtime and return error to the
6786- // caller if they are violated, instead of using an assert.
6787- UPB_ASSERT (field -> descriptortype == kUpb_FieldType_Message ||
6788- field -> descriptortype == kUpb_FieldType_Group );
6789- if (sub -> ext & kUpb_ExtMode_IsMapEntry ) {
6790- UPB_ASSERT (field -> descriptortype == kUpb_FieldType_Message );
6791- field -> mode = (field -> mode & ~kUpb_FieldMode_Mask ) | kUpb_FieldMode_Map ;
6785+ UPB_ASSERT (sub );
6786+
6787+ const bool sub_is_map = sub -> ext & kUpb_ExtMode_IsMapEntry ;
6788+
6789+ switch (field -> descriptortype ) {
6790+ case kUpb_FieldType_Message :
6791+ if (sub_is_map ) {
6792+ const bool table_is_map = table -> ext & kUpb_ExtMode_IsMapEntry ;
6793+ if (UPB_UNLIKELY (table_is_map )) return false;
6794+
6795+ field -> mode = (field -> mode & ~kUpb_FieldMode_Mask ) | kUpb_FieldMode_Map ;
6796+ }
6797+ break ;
6798+
6799+ case kUpb_FieldType_Group :
6800+ if (UPB_UNLIKELY (sub_is_map )) return false;
6801+ break ;
6802+
6803+ default :
6804+ return false;
67926805 }
67936806
67946807 upb_MiniTableSub * table_sub = (void * )& table -> subs [field -> submsg_index ];
You can’t perform that action at this time.
0 commit comments