Protoc crashes on a dotted option that leaves required fields unset

オープン
#31,344 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp
領域
compilers

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C++
スター
72.2k
フォーク
16.4k
平均マージ
1日 8時間
マージ済み PR(30日)
342

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

protocolbuffers/protobuf のほかの issue

protocolbuffers/protobuf の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。