tdp + delim + lenpre

PiperOrigin-RevId: 627396755
pull/16726/head
Hong Shin 2024-04-23 08:29:48 -07:00 committed by Copybara-Service
parent fefec68753
commit 31c244b080
2 changed files with 74 additions and 29 deletions

View File

@ -2291,14 +2291,18 @@ PROTOBUF_NOINLINE const char* TcParser::MpMessage(PROTOBUF_TC_PARAM_DECL) {
const uint16_t type_card = entry.type_card;
const uint16_t card = type_card & field_layout::kFcMask;
const uint32_t decoded_tag = data.tag();
const uint32_t decoded_wiretype = decoded_tag & 7;
const bool is_group =
decoded_wiretype == WireFormatLite::WIRETYPE_START_GROUP;
// Check for repeated parsing:
if (card == field_layout::kFcRepeated) {
const uint16_t rep = type_card & field_layout::kRepMask;
switch (rep) {
case field_layout::kRepMessage:
switch (decoded_wiretype) {
case WireFormatLite::WIRETYPE_LENGTH_DELIMITED:
PROTOBUF_MUSTTAIL return MpRepeatedMessageOrGroup<is_split, false>(
PROTOBUF_TC_PARAM_PASS);
case field_layout::kRepGroup:
case WireFormatLite::WIRETYPE_START_GROUP:
PROTOBUF_MUSTTAIL return MpRepeatedMessageOrGroup<is_split, true>(
PROTOBUF_TC_PARAM_PASS);
default:
@ -2306,29 +2310,14 @@ PROTOBUF_NOINLINE const char* TcParser::MpMessage(PROTOBUF_TC_PARAM_DECL) {
}
}
const uint32_t decoded_tag = data.tag();
const uint32_t decoded_wiretype = decoded_tag & 7;
const uint16_t rep = type_card & field_layout::kRepMask;
const bool is_group = rep == field_layout::kRepGroup;
// Validate wiretype:
switch (rep) {
case field_layout::kRepMessage:
if (decoded_wiretype != WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
goto fallback;
}
break;
case field_layout::kRepGroup:
if (decoded_wiretype != WireFormatLite::WIRETYPE_START_GROUP) {
goto fallback;
}
break;
default: {
fallback:
PROTOBUF_MUSTTAIL return table->fallback(PROTOBUF_TC_PARAM_PASS);
}
// If we don't see a wiretype of START_GROUP or DELIM even though we're in the
// entry point for MpMessage, something is wrong. Bail out!
if (decoded_wiretype != WireFormatLite::WIRETYPE_START_GROUP &&
decoded_wiretype != WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
PROTOBUF_MUSTTAIL return table->fallback(PROTOBUF_TC_PARAM_PASS);
}
const bool is_oneof = card == field_layout::kFcOneof;
bool need_init = false;
if (card == field_layout::kFcOptional) {
@ -2380,14 +2369,10 @@ const char* TcParser::MpRepeatedMessageOrGroup(PROTOBUF_TC_PARAM_DECL) {
// Validate wiretype:
if (!is_group) {
ABSL_DCHECK_EQ(type_card & field_layout::kRepMask,
static_cast<uint16_t>(field_layout::kRepMessage));
if (decoded_wiretype != WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
PROTOBUF_MUSTTAIL return table->fallback(PROTOBUF_TC_PARAM_PASS);
}
} else {
ABSL_DCHECK_EQ(type_card & field_layout::kRepMask,
static_cast<uint16_t>(field_layout::kRepGroup));
if (decoded_wiretype != WireFormatLite::WIRETYPE_START_GROUP) {
PROTOBUF_MUSTTAIL return table->fallback(PROTOBUF_TC_PARAM_PASS);
}

View File

@ -804,6 +804,45 @@ static const char* HandleMessage(Message* msg, const char* ptr,
return ptr;
}
static bool IsMismatchAllowed(const FieldDescriptor* field_descriptor,
WireFormatLite::WireType wire_type, bool is_lazy,
bool is_map) {
if (is_map) {
return false;
}
switch (field_descriptor->type()) {
case FieldDescriptor::TYPE_GROUP:
return wire_type == WireFormatLite::WIRETYPE_LENGTH_DELIMITED ||
wire_type == WireFormatLite::WIRETYPE_START_GROUP;
case FieldDescriptor::TYPE_MESSAGE:
return is_lazy ? wire_type == WireFormatLite::WIRETYPE_LENGTH_DELIMITED
: wire_type == WireFormatLite::WIRETYPE_LENGTH_DELIMITED ||
wire_type == WireFormatLite::WIRETYPE_START_GROUP;
case FieldDescriptor::TYPE_STRING:
case FieldDescriptor::TYPE_BYTES:
return false;
case FieldDescriptor::TYPE_INT32:
case FieldDescriptor::TYPE_INT64:
case FieldDescriptor::TYPE_UINT32:
case FieldDescriptor::TYPE_UINT64:
case FieldDescriptor::TYPE_SINT32:
case FieldDescriptor::TYPE_SINT64:
case FieldDescriptor::TYPE_BOOL:
case FieldDescriptor::TYPE_ENUM:
return wire_type == WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
case FieldDescriptor::TYPE_FIXED32:
case FieldDescriptor::TYPE_SFIXED32:
case FieldDescriptor::TYPE_FLOAT:
return wire_type == WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
case FieldDescriptor::TYPE_FIXED64:
case FieldDescriptor::TYPE_SFIXED64:
case FieldDescriptor::TYPE_DOUBLE:
return wire_type == WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
default:
return false;
}
}
const char* WireFormat::_InternalParse(Message* msg, const char* ptr,
internal::ParseContext* ctx) {
const Descriptor* descriptor = msg->GetDescriptor();
@ -852,6 +891,27 @@ const char* WireFormat::_InternalParseAndMergeField(
return internal::UnknownFieldParse(
tag, reflection->MutableUnknownFields(msg), ptr, ctx);
}
auto zget_tag_wire_type = WireFormatLite::GetTagWireType(tag);
auto zwire_type_for_field_type = WireTypeForFieldType(field->type());
auto zfield_type = field->type();
(void)zget_tag_wire_type;
(void)zwire_type_for_field_type;
(void)zfield_type;
bool is_lazy = reflection->IsLazyField(field);
bool is_map = field->is_map();
if (WireFormatLite::GetTagWireType(tag) !=
WireTypeForFieldType(field->type()) &&
!IsMismatchAllowed(field, WireFormatLite::GetTagWireType(tag), is_lazy,
is_map)) {
// mismatched wiretype;
return internal::UnknownFieldParse(
tag, reflection->MutableUnknownFields(msg), ptr, ctx);
}
if (field->type() == FieldDescriptor::TYPE_MESSAGE ||
field->type() == FieldDescriptor::TYPE_GROUP) {
return HandleMessage(msg, ptr, ctx, tag, reflection, field);
}
if (WireFormatLite::GetTagWireType(tag) !=
WireTypeForFieldType(field->type())) {
if (field->is_packable() && WireFormatLite::GetTagWireType(tag) ==