diff --git a/conformance/BUILD.bazel b/conformance/BUILD.bazel index ae9c18c0ed..384bb56563 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 fd21da7212..bd0f59b012 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" @@ -1303,6 +1304,24 @@ void BinaryAndJsonConformanceSuiteImpl::TestIllegalTags() { } } +template +void BinaryAndJsonConformanceSuiteImpl::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 void BinaryAndJsonConformanceSuiteImpl::TestOneofMessage() { MessageType message; @@ -1467,6 +1486,8 @@ void BinaryAndJsonConformanceSuiteImpl::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 a510e9a6b8..325a76e3ba 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();