From 7ad307eea83145b777febc92088eb4ec213c1f55 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 27 Jan 2023 15:40:39 -0800 Subject: [PATCH] Added assert that message-type map values must be linked. PiperOrigin-RevId: 505225954 --- upb/wire/decode.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/upb/wire/decode.c b/upb/wire/decode.c index f949284151..37ea81e9f2 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -587,14 +587,18 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, *map_p = map; } - /* Parse map entry. */ + // Parse map entry. memset(&ent, 0, sizeof(ent)); if (entry->fields[1].descriptortype == kUpb_FieldType_Message || entry->fields[1].descriptortype == kUpb_FieldType_Group) { - /* Create proactively to handle the case where it doesn't appear. */ - ent.data.v.val = - upb_value_ptr(_upb_Message_New(entry->subs[0].submsg, &d->arena)); + const upb_MiniTable* submsg_table = entry->subs[0].submsg; + // Any sub-message entry must be linked. We do not allow dynamic tree + // shaking in this case. + UPB_ASSERT(submsg_table); + + // Create proactively to handle the case where it doesn't appear. */ + ent.data.v.val = upb_value_ptr(_upb_Message_New(submsg_table, &d->arena)); } const char* start = ptr;