Repository navigation
protobuf/tests: Improve handling of descriptor library parse failures - #48108
Conversation
|
I'm not sure what this does. Should an API maintainer be assigned? |
|
i think its pretty straightforward and test only - it prevents a warning emitted - this one INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc:
external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc:
external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString());
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
|
| !file_descriptor_proto.ParseFromString(file_descriptor_bytes)) { | ||
| // Embedded descriptors are generated at build time; a failure here is a | ||
| // build bug, not a runtime condition. Skip rather than register garbage. | ||
| return; |
There was a problem hiding this comment.
This fixes the nodiscard warning, but the failure is still dropped silently. If this ever happens, the only symptom is a later "Could not find descriptor for: X" error, far from the real cause. The comment says this is a build bug, so could we report it here? An assert, or an ABSL_LOG(DFATAL), would make it loud in debug builds and still skip the bad descriptor in release.
Related: BuildFile() on L72 can also fail (it returns nullptr). It isn't nodiscard, so there's no warning, but it's the same silent-failure pattern. Worth handling the same way?
There was a problem hiding this comment.
re BuildFile - wasnt sure but will add
There was a problem hiding this comment.
Both now ABSL_LOG(DFATAL) (fatal in debug, skip in release), and BuildFile() returning nullptr is handled the same way. Covered by InvalidDescriptorsAreNotRegistered and the new UnbuildableDescriptorsAreNotRegistered.
| !file_descriptor_proto.ParseFromString(file_descriptor_bytes)) { | ||
| // Embedded descriptors are generated at build time; a failure here is a | ||
| // build bug, not a runtime condition. Skip rather than register garbage. | ||
| return; |
There was a problem hiding this comment.
Same as in text_format_transcoder.cc: the failure is skipped silently, and BuildFile() on L29 also ignores its result. It would be good to surface both.
There was a problem hiding this comment.
Same treatment here: parse/unescape and BuildFile() failures both ABSL_LOG(DFATAL).
| 0, 0, | ||
| absl::StrFormat("Could not parse dynamic message for: %s", message.GetTypeName())); | ||
| } | ||
| return nullptr; |
There was a problem hiding this comment.
This changes behavior for the main production caller. Envoy::createReflectableMessage() (source/common/protobuf/create_reflectable_message.cc) only checks the result with ASSERT, which is compiled out in release builds. A parse failure used to give a partly filled message; now release callers would dereference nullptr. Failing loudly is probably the right call, and this path should only fail if descriptors don't match. Could the PR description mention it, or could that caller handle nullptr explicitly?
There was a problem hiding this comment.
createReflectableMessage() now uses RELEASE_ASSERT rather than ASSERT, so release builds fail loudly instead of dereferencing nullptr. Also noted in the PR description.
|
/wait pending comments being flushed |
|
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
Signed-off-by: Ryan Northey <[email protected]>
Log parse and build failures of embedded file descriptors with ABSL_LOG(DFATAL), so they are fatal in debug builds and skipped in release builds, and check the result of BuildFile(). createReflectableMessage() now RELEASE_ASSERTs on a null dynamic message, as callers dereference it. Signed-off-by: Ryan Northey <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the protobuf descriptor and dynamic-message error-handling changes.
No open issues 🎉
What changed in this PR
This PR improves failure handling in Envoy’s protobuf descriptor and dynamic-message helpers, addressing unchecked parse results and preventing failed conversions from returning partially parsed messages.
Changes:
- Check descriptor decoding, parsing, and registration results, with diagnostics for failures.
- Return null when dynamic-message parsing fails and enforce a release-mode assertion in the reflectable-message wrapper.
- Add regression tests for invalid descriptors and message parse failures, with supporting test dependencies.
| File | Description |
|---|---|
source/common/protobuf/create_reflectable_message.cc |
Enforces non-null results in release builds. |
api/bazel/cc_proto_descriptor_library/text_format_transcoder.cc |
Checks descriptor decoding, parsing, and registration failures. |
api/bazel/cc_proto_descriptor_library/testdata/text_format_transcoder_test.cc |
Tests invalid descriptors and subsequent valid registration. |
api/bazel/cc_proto_descriptor_library/testdata/create_dynamic_message_test.cc |
Tests parse failures and error reporting. |
api/bazel/cc_proto_descriptor_library/testdata/BUILD |
Adds dependencies needed by the new tests. |
api/bazel/cc_proto_descriptor_library/file_descriptor_info.cc |
Adds failure checks to the shared descriptor loader. |
api/bazel/cc_proto_descriptor_library/create_dynamic_message.cc |
Reports parse failures and returns null. |
Review effort: Balanced
|
/retest flakey android |
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> Backport note (release/v1.37): the test deps use this branch's `@com_google_absl`. (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> Backport note (release/v1.37): the test deps use this branch's `@com_google_absl`. (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> Backport note (release/v1.37): the test deps use this branch's `@com_google_absl`. (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> Backport note (release/v1.37): the test deps use this branch's `@com_google_absl`. (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
…envoyproxy#48108) fix following warning ```console INFO: From Compiling bazel/cc_proto_descriptor_library/text_format_transcoder.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/text_format_transcoder.cc:66:3: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 66 | file_descriptor_proto.ParseFromString(file_descriptor_bytes); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. INFO: From Compiling bazel/cc_proto_descriptor_library/create_dynamic_message.cc: external/envoy_api+/bazel/cc_proto_descriptor_library/create_dynamic_message.cc:25:5: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] 25 | dynamic_message->ParsePartialFromString(message.SerializePartialAsString()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` --------- Signed-off-by: Ryan Northey <[email protected]> Backport note (release/v1.37): the test deps use this branch's `@com_google_absl`. (cherry picked from commit 9c88f1c) Signed-off-by: Ryan Northey <[email protected]>
fix following warning