aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/message_unittest.inc
diff options
context:
space:
mode:
authorJosh Haberman <jhaberman@gmail.com>2018-09-04 10:58:54 -0700
committerJosh Haberman <jhaberman@gmail.com>2018-09-04 10:58:54 -0700
commitd61aede89cf188367766b971f59cf57d7835d8e8 (patch)
treea19842c62c3c8f51389912ecafdf932d0a572bea /src/google/protobuf/message_unittest.inc
parent45d03a977193d1dcce5251e4bffe17bf0ba738ec (diff)
downloadprotobuf-d61aede89cf188367766b971f59cf57d7835d8e8.tar.gz
protobuf-d61aede89cf188367766b971f59cf57d7835d8e8.tar.bz2
protobuf-d61aede89cf188367766b971f59cf57d7835d8e8.zip
Down-integrate from google3.
Diffstat (limited to 'src/google/protobuf/message_unittest.inc')
-rw-r--r--src/google/protobuf/message_unittest.inc62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/google/protobuf/message_unittest.inc b/src/google/protobuf/message_unittest.inc
index 0b9d565f..23deaa25 100644
--- a/src/google/protobuf/message_unittest.inc
+++ b/src/google/protobuf/message_unittest.inc
@@ -567,6 +567,68 @@ TEST(MESSAGE_FACTORY_TEST_NAME, GeneratedFactoryUnknownType) {
nullptr);
}
+TEST(MESSAGE_TEST_NAME, MOMIParserEdgeCases) {
+ {
+ UNITTEST::TestAllTypes msg;
+ // Parser ends in last 16 bytes of buffer due to a 0.
+ string data;
+ // 12 bytes of data
+ for (int i = 0; i < 4; i++) data += "\370\1\1";
+ // 13 byte is terminator
+ data += '\0'; // Terminator
+ // followed by the rest of the stream
+ // space is ascii 32 so no end group
+ data += string(30, ' ');
+ io::ArrayInputStream zcis(data.data(), data.size(), 17);
+ io::CodedInputStream cis(&zcis);
+ EXPECT_TRUE(msg.MergePartialFromCodedStream(&cis));
+ EXPECT_EQ(cis.CurrentPosition(), 3 * 4 + 1);
+ }
+ {
+ // Parser ends in last 16 bytes of buffer due to a end-group.
+ // Must use a message that is a group. Otherwise ending on a group end is
+ // a failure.
+ UNITTEST::TestAllTypes::OptionalGroup msg;
+ string data;
+ for (int i = 0; i < 3; i++) data += "\370\1\1";
+ data += '\14'; // Octal end-group tag 12 (1 * 8 + 4(
+ data += string(30, ' ');
+ io::ArrayInputStream zcis(data.data(), data.size(), 17);
+ io::CodedInputStream cis(&zcis);
+ EXPECT_TRUE(msg.MergePartialFromCodedStream(&cis));
+ EXPECT_EQ(cis.CurrentPosition(), 3 * 3 + 1);
+ EXPECT_TRUE(cis.LastTagWas(12));
+ }
+ {
+ // Parser ends in last 16 bytes of buffer due to a end-group. But is inside
+ // a length delimited field.
+ // a failure.
+ UNITTEST::TestAllTypes::OptionalGroup msg;
+ string data;
+ data += "\22\3foo";
+ data += '\14'; // Octal end-group tag 12 (1 * 8 + 4(
+ data += string(30, ' ');
+ io::ArrayInputStream zcis(data.data(), data.size(), 17);
+ io::CodedInputStream cis(&zcis);
+ EXPECT_TRUE(msg.MergePartialFromCodedStream(&cis));
+ EXPECT_EQ(cis.CurrentPosition(), 6);
+ EXPECT_TRUE(cis.LastTagWas(12));
+ }
+ {
+ // Parser fails when ending on 0 if from ZeroCopyInputStream
+ UNITTEST::TestAllTypes msg;
+ string data;
+ // 12 bytes of data
+ for (int i = 0; i < 4; i++) data += "\370\1\1";
+ // 13 byte is terminator
+ data += '\0'; // Terminator
+ data += string(30, ' ');
+ io::ArrayInputStream zcis(data.data(), data.size(), 17);
+ EXPECT_FALSE(msg.ParsePartialFromZeroCopyStream(&zcis));
+ }
+}
+
+
} // namespace protobuf
} // namespace google