Skip to content

Commit

Permalink
Test if a tag with unknown wire type (0x6 or 0x7) causes parsing fail…
Browse files Browse the repository at this point in the history
…ures.

PiperOrigin-RevId: 634878920
  • Loading branch information
protobuf-github-bot authored and Copybara-Service committed May 17, 2024
1 parent 11c27df commit 1f82080
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions conformance/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down
21 changes: 21 additions & 0 deletions conformance/binary_json_conformance_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1467,6 +1486,8 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::RunAllTests() {

TestIllegalTags();

TestUnknownWireType();

int64_t kInt64Min = -9223372036854775808ULL;
int64_t kInt64Max = 9223372036854775807ULL;
uint64_t kUint64Max = 18446744073709551615ULL;
Expand Down
1 change: 1 addition & 0 deletions conformance/binary_json_conformance_suite.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1f82080

Please sign in to comment.