Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(665)

Unified Diff: third_party/protobuf/src/google/protobuf/message_unittest.cc

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Update to new HEAD (b7632464b4) + restore GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/src/google/protobuf/message_unittest.cc
diff --git a/third_party/protobuf/src/google/protobuf/message_unittest.cc b/third_party/protobuf/src/google/protobuf/message_unittest.cc
index d668a1a6bb62e76d372502c8c693fcab48ebdbc6..3af05808f60f624a80df25d996216ebce9a9680e 100644
--- a/third_party/protobuf/src/google/protobuf/message_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/message_unittest.cc
@@ -265,6 +265,24 @@ TEST(MessageTest, CheckOverflow) {
EXPECT_FALSE(message.AppendToCord(&serialized));
}
+TEST(MessageTest, CheckBigOverflow) {
+ unittest::TestAllTypes message;
+ // Create a message with size just over 4GB. We should be able to detect this
+ // too, even though it will make a plain "int" wrap back to a positive number.
+ const string data(1024, 'x');
+ Cord one_megabyte;
+ for (int i = 0; i < 1024; i++) {
+ one_megabyte.Append(data);
+ }
+
+ for (int i = 0; i < 4 * 1024 + 1; ++i) {
+ message.add_repeated_cord()->CopyFrom(one_megabyte);
+ }
+
+ Cord serialized;
+ EXPECT_FALSE(message.AppendToCord(&serialized));
+}
+
#endif // PROTOBUF_HAS_DEATH_TEST
namespace {
@@ -272,6 +290,12 @@ namespace {
class NegativeByteSize : public unittest::TestRequired {
public:
virtual int ByteSize() const { return -1; }
+
+ // The implementation of ByteSizeLong() from MessageLite, to simulate what
+ // would happen if TestRequired *hadn't* overridden it already.
+ virtual size_t ByteSizeLong() const {
+ return static_cast<unsigned int>(ByteSize());
+ }
};
} // namespace
@@ -319,6 +343,18 @@ TEST(MessageTest, ParseFailsOnInvalidMessageEnd) {
EXPECT_FALSE(message.ParseFromArray("\014", 1));
}
+// Regression test for b/23630858
+TEST(MessageTest, MessageIsStillValidAfterParseFails) {
+ unittest::TestAllTypes message;
+
+ // 9 0xFFs for the "optional_uint64" field.
+ string invalid_data = "\x20\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF";
+
+ EXPECT_FALSE(message.ParseFromString(invalid_data));
+ message.Clear();
+ EXPECT_EQ(0, message.optional_uint64());
+}
+
namespace {
void ExpectMessageMerged(const unittest::TestAllTypes& message) {

Powered by Google App Engine
This is Rietveld 408576698