Skip to content

Commit

Permalink
protozero: DCHECK against zero field ids
Browse files Browse the repository at this point in the history
Zero field ids aren't valid protobuf, so DCHECK that we never try to
create messages with such fields. Note that we don't add DCHECKs to
primitive field writers to avoid adding too much overhead in debug
builds.

Bug: 298923683
Change-Id: If9f134ec41e664a8548eaaf6c142081714b1fac1
  • Loading branch information
skyostil committed Sep 12, 2023
1 parent aa74d0a commit 2fa2728
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/protozero/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void Message::AppendString(uint32_t field_id, const char* str) {
}

void Message::AppendBytes(uint32_t field_id, const void* src, size_t size) {
PERFETTO_DCHECK(field_id);
if (nested_message_)
EndNestedMessage();

Expand All @@ -90,6 +91,7 @@ void Message::AppendBytes(uint32_t field_id, const void* src, size_t size) {
size_t Message::AppendScatteredBytes(uint32_t field_id,
ContiguousMemoryRange* ranges,
size_t num_ranges) {
PERFETTO_DCHECK(field_id);
if (nested_message_)
EndNestedMessage();

Expand Down Expand Up @@ -143,6 +145,7 @@ uint32_t Message::Finalize() {
}

Message* Message::BeginNestedMessageInternal(uint32_t field_id) {
PERFETTO_DCHECK(field_id);
if (nested_message_)
EndNestedMessage();

Expand Down

0 comments on commit 2fa2728

Please sign in to comment.