diff options
author | Protobuf Team Bot <protobuf-github-bot@google.com> | 2024-05-17 13:58:38 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-05-17 14:03:07 -0700 |
commit | 1f8208031a07ec384dd9f86e41a92fd715e88e37 (patch) | |
tree | 59cfd8a134447d3534546545d1951f5f008f8656 | |
parent | 11c27dfa4b4dd2f79b722897bc04a297c2a35c26 (diff) | |
download | protobuf-upstream-main.tar.gz |
Test if a tag with unknown wire type (0x6 or 0x7) causes parsing failures.upstream-main
PiperOrigin-RevId: 634878920
-rw-r--r-- | conformance/BUILD.bazel | 1 | ||||
-rw-r--r-- | conformance/binary_json_conformance_suite.cc | 21 | ||||
-rw-r--r-- | conformance/binary_json_conformance_suite.h | 1 |
3 files changed, 23 insertions, 0 deletions
diff --git a/conformance/BUILD.bazel b/conformance/BUILD.bazel index ae9c18c0e..384bb5656 100644 --- a/conformance/BUILD.bazel +++ b/conformance/BUILD.bazel @@ -178,6 +178,7 @@ cc_library( "@com_google_absl//absl/log:die_if_null", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", "@jsoncpp", ], ) diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index fd21da721..bd0f59b01 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -22,6 +22,7 @@ #include "absl/log/die_if_null.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" +#include "absl/strings/str_format.h" #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" #include "conformance/conformance.pb.h" @@ -1304,6 +1305,24 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::TestIllegalTags() { } template <typename MessageType> +void BinaryAndJsonConformanceSuiteImpl<MessageType>::TestUnknownWireType() { + for (uint8_t type : {0x6, 0x7}) { + for (uint8_t field = 0; field < 4; ++field) { + for (uint8_t value = 0; value < 4; ++value) { + std::string name = absl::StrFormat("UnknownWireType%d_Field%d_Verion%d", + type, field, value); + + char data[2]; + data[0] = (field << 3) | type; // unknown wire type. + data[1] = value; + std::string proto = {data, 2}; + ExpectParseFailureForProto(proto, name, REQUIRED); + } + } + } +} + +template <typename MessageType> void BinaryAndJsonConformanceSuiteImpl<MessageType>::TestOneofMessage() { MessageType message; message.set_oneof_uint32(0); @@ -1467,6 +1486,8 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::RunAllTests() { TestIllegalTags(); + TestUnknownWireType(); + int64_t kInt64Min = -9223372036854775808ULL; int64_t kInt64Max = 9223372036854775807ULL; uint64_t kUint64Max = 18446744073709551615ULL; diff --git a/conformance/binary_json_conformance_suite.h b/conformance/binary_json_conformance_suite.h index a510e9a6b..325a76e3b 100644 --- a/conformance/binary_json_conformance_suite.h +++ b/conformance/binary_json_conformance_suite.h @@ -143,6 +143,7 @@ class BinaryAndJsonConformanceSuiteImpl { ConformanceLevel level); void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type); void TestIllegalTags(); + void TestUnknownWireType(); void TestOneofMessage(); void TestUnknownMessage(); void TestUnknownOrdering(); |