Protoc crashes on a dotted option that leaves required fields unset

Open
#31,344 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
compilers

Research direction

The report points to option interpretation and ValidateTargetConstraints in the protoc command line interface. Start by tracing how dotted and aggregate custom option values are merged and where required fields are checked; reproduce with the three .proto examples in the issue. Done means all three cases behave consistently, and an incomplete option reports an error instead of aborting.

Written by the indexing model from the issue text.

Description

bug untriaged

What version of protobuf and what language are you using?

Version: v36.2 (libprotoc 36.2)
Language: .proto files compiled with protoc (custom options)

What supported operating system version are you using (e.g. Linux, Windows) ?
macOS (arm64)

What supported runtime / compiler version are you using (e.g. python version, gcc version)
The prebuilt protoc 36.2 release binary.

What did you do?
A custom option whose message has required fields:

// foo.proto
syntax = "proto2";

import "google/protobuf/descriptor.proto";

message Foo {
  required string a = 1;
  required string b = 2;
}

extend google.protobuf.FileOptions {
  optional Foo foo = 50000;
}

These three files each set the option a different way:

// dotted.proto
syntax = "proto2";
import "foo.proto";
option (foo).a = "x";
option (foo).b = "y";
// literal_then_dotted.proto
syntax = "proto2";
import "foo.proto";
option (foo) = { a: "x" };
option (foo).b = "y";
// partial.proto
syntax = "proto2";
import "foo.proto";
option (foo).a = "x";

Compiled each with protoc -I. -o /dev/null <file>.

What did you expect to see

The required-field check should be consistent. Dotted options already merge into one value. I expected required fields to be checked on that final merged value with an ordinary error:

  • dotted.proto: accepted.
  • literal_then_dotted.proto: accepted. The final value is { a: "x" b: "y" }, the same as dotted.proto.
  • partial.proto: a normal error such as Option "(foo)" is missing required fields: b, with exit code 1.

What did you see instead?

  • dotted.proto: accepted (exit 0).
  • literal_then_dotted.proto: rejected, even though the merged value is complete:
literal_then_dotted.proto:5:16: Error while parsing option value for "foo": Message missing required fields: b
  • partial.proto: protoc logs an error and then aborts on a failed CHECK (exit code 134):
E... message_lite.cc:200] Can't parse message of type "google.protobuf.FileOptions" because it is missing required fields: (foo).b
F... command_line_interface.cc:1259] Check failed: dynamic_message->ParseFromString(serialized)
*** Check failure stack trace: ***
    @ ... absl::lts_20250814::log_internal::LogMessage::Flush()
    @ ... google::protobuf::compiler::(anonymous namespace)::ValidateTargetConstraints()
    @ ... google::protobuf::compiler::CommandLineInterface::Run()
    @ ... google::protobuf::compiler::ProtobufMain()

Anything else we should know about your project / environment

Required fields are checked at two different points:

  1. When an aggregate ({ ... }) option value is parsed, each literal must be complete on its own, even if later options fill in the rest.
  2. The merged options for dotted names aren't checked during option interpretation. The first check that sees them is the ParseFromString in ValidateTargetConstraints, which hits a CHECK and aborts.

As a result, merging a literal with later dotted options behaves differently from merging dotted options with each other, and a partially set option crashes instead of reporting an error.

A single check on each element's final merged options during option interpretation would fix both.

Dominant language
C++
Stars
72.2k
Forks
16.4k
Avg merge
1d 8h
Merged PRs (30d)
342

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from protocolbuffers/protobuf

All issues in protocolbuffers/protobuf

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.