Test if a tag with unknown wire type (0x6 or 0x7) causes parsing failures.

PiperOrigin-RevId: 634878920
pull/16879/head
Protobuf Team Bot 8 months ago committed by Copybara-Service
parent 11c27dfa4b
commit 1f8208031a
  1. 1
      conformance/BUILD.bazel
  2. 21
      conformance/binary_json_conformance_suite.cc
  3. 1
      conformance/binary_json_conformance_suite.h

@ -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",
],
)

@ -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<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;
@ -1467,6 +1486,8 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::RunAllTests() {
TestIllegalTags();
TestUnknownWireType();
int64_t kInt64Min = -9223372036854775808ULL;
int64_t kInt64Max = 9223372036854775807ULL;
uint64_t kUint64Max = 18446744073709551615ULL;

@ -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();

Loading…
Cancel
Save