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

Unified Diff: third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc

Issue 2599263002: third_party/protobuf: Update to HEAD (f52e188fe4) (Closed)
Patch Set: Address comments Created 4 years 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/io/coded_stream_unittest.cc
diff --git a/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc b/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc
index a8108e4572bc5111648e12e8b9d2fe1cfe4d2fba..31574d5be35b3ca6c81fc25ceff30b9ffbddddbe 100644
--- a/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc
@@ -58,6 +58,7 @@
#define ULL(x) GOOGLE_ULONGLONG(x)
namespace google {
+
namespace protobuf {
namespace io {
namespace {
@@ -134,7 +135,7 @@ class CodedStreamTest : public testing::Test {
// for further information.
static void SetupTotalBytesLimitWarningTest(
int total_bytes_limit, int warning_threshold,
- vector<string>* out_errors, vector<string>* out_warnings);
+ std::vector<string>* out_errors, std::vector<string>* out_warnings);
// Buffer used during most of the tests. This assumes tests run sequentially.
static const int kBufferSize = 1024 * 64;
@@ -244,7 +245,7 @@ TEST_F(CodedStreamTest, EmptyInputBeforeEos) {
int count_;
} in;
CodedInputStream input(&in);
- input.ReadTag();
+ input.ReadTagNoLastTag();
EXPECT_TRUE(input.ConsumedEntireMessage());
}
@@ -445,6 +446,21 @@ TEST_2D(CodedStreamTest, ReadVarint32Error, kVarintErrorCases, kBlockSizes) {
EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint32(&value));
}
+TEST_2D(CodedStreamTest, ReadVarint32Error_LeavesValueInInitializedState,
+ kVarintErrorCases, kBlockSizes) {
+ memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
+ ArrayInputStream input(buffer_, kVarintErrorCases_case.size,
+ kBlockSizes_case);
+ CodedInputStream coded_input(&input);
+
+ uint32 value = 0;
+ EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint32(&value));
+ // While the specific value following a failure is not critical, we do want to
+ // ensure that it doesn't get set to an uninitialized value. (This check fails
+ // in MSAN mode if value has been set to an uninitialized value.)
+ EXPECT_EQ(value, value);
+}
+
TEST_2D(CodedStreamTest, ReadVarint64Error, kVarintErrorCases, kBlockSizes) {
memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
ArrayInputStream input(buffer_, kVarintErrorCases_case.size,
@@ -455,6 +471,21 @@ TEST_2D(CodedStreamTest, ReadVarint64Error, kVarintErrorCases, kBlockSizes) {
EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint64(&value));
}
+TEST_2D(CodedStreamTest, ReadVarint64Error_LeavesValueInInitializedState,
+ kVarintErrorCases, kBlockSizes) {
+ memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
+ ArrayInputStream input(buffer_, kVarintErrorCases_case.size,
+ kBlockSizes_case);
+ CodedInputStream coded_input(&input);
+
+ uint64 value = 0;
+ EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint64(&value));
+ // While the specific value following a failure is not critical, we do want to
+ // ensure that it doesn't get set to an uninitialized value. (This check fails
+ // in MSAN mode if value has been set to an uninitialized value.)
+ EXPECT_EQ(value, value);
+}
+
// -------------------------------------------------------------------
// VarintSize
@@ -494,6 +525,28 @@ TEST_1D(CodedStreamTest, VarintSize64, kVarintSizeCases) {
CodedOutputStream::VarintSize64(kVarintSizeCases_case.value));
}
+TEST_F(CodedStreamTest, VarintSize32PowersOfTwo) {
+ int expected = 1;
+ for (int i = 1; i < 32; i++) {
+ if (i % 7 == 0) {
+ expected += 1;
+ }
+ EXPECT_EQ(expected,
+ CodedOutputStream::VarintSize32(static_cast<uint32>(0x1u << i)));
+ }
+}
+
+TEST_F(CodedStreamTest, VarintSize64PowersOfTwo) {
+ int expected = 1;
+ for (int i = 1; i < 64; i++) {
+ if (i % 7 == 0) {
+ expected += 1;
+ }
+ EXPECT_EQ(expected, CodedOutputStream::VarintSize64(
+ static_cast<uint64>(0x1ull << i)));
+ }
+}
+
// -------------------------------------------------------------------
// Fixed-size int tests
@@ -1176,7 +1229,7 @@ TEST_F(CodedStreamTest, TotalBytesLimit) {
EXPECT_TRUE(coded_input.ReadString(&str, 16));
EXPECT_EQ(0, coded_input.BytesUntilTotalBytesLimit());
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog error_log;
@@ -1210,7 +1263,7 @@ TEST_F(CodedStreamTest, TotalBytesLimitNotValidMessageEnd) {
// Read a tag. Should fail, but report being a valid endpoint since it's
// a regular limit.
- EXPECT_EQ(0, coded_input.ReadTag());
+ EXPECT_EQ(0, coded_input.ReadTagNoLastTag());
EXPECT_TRUE(coded_input.ConsumedEntireMessage());
// Pop the limit.
@@ -1218,7 +1271,7 @@ TEST_F(CodedStreamTest, TotalBytesLimitNotValidMessageEnd) {
// Read a tag. Should fail, and report *not* being a valid endpoint, since
// this time we're hitting the total bytes limit.
- EXPECT_EQ(0, coded_input.ReadTag());
+ EXPECT_EQ(0, coded_input.ReadTagNoLastTag());
EXPECT_FALSE(coded_input.ConsumedEntireMessage());
}
@@ -1228,7 +1281,7 @@ TEST_F(CodedStreamTest, TotalBytesLimitNotValidMessageEnd) {
// vectors.
void CodedStreamTest::SetupTotalBytesLimitWarningTest(
int total_bytes_limit, int warning_threshold,
- vector<string>* out_errors, vector<string>* out_warnings) {
+ std::vector<string>* out_errors, std::vector<string>* out_warnings) {
ArrayInputStream raw_input(buffer_, sizeof(buffer_), 128);
ScopedMemoryLog scoped_log;
@@ -1244,25 +1297,21 @@ void CodedStreamTest::SetupTotalBytesLimitWarningTest(
}
TEST_F(CodedStreamTest, TotalBytesLimitWarning) {
- vector<string> errors;
- vector<string> warnings;
+ std::vector<string> errors;
+ std::vector<string> warnings;
SetupTotalBytesLimitWarningTest(10240, 1024, &errors, &warnings);
EXPECT_EQ(0, errors.size());
- ASSERT_EQ(2, warnings.size());
- EXPECT_PRED_FORMAT2(testing::IsSubstring,
- "Reading dangerously large protocol message. If the message turns out to "
- "be larger than 10240 bytes, parsing will be halted for security reasons.",
- warnings[0]);
+ EXPECT_EQ(1, warnings.size());
EXPECT_PRED_FORMAT2(testing::IsSubstring,
"The total number of bytes read was 2048",
- warnings[1]);
+ warnings[0]);
}
TEST_F(CodedStreamTest, TotalBytesLimitWarningDisabled) {
- vector<string> errors;
- vector<string> warnings;
+ std::vector<string> errors;
+ std::vector<string> warnings;
// Test with -1
SetupTotalBytesLimitWarningTest(10240, -1, &errors, &warnings);
@@ -1361,7 +1410,7 @@ TEST_F(CodedStreamTest, InputOver2G) {
// input.BackUp() with the correct number of bytes on destruction.
ReallyBigInputStream input;
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog error_log;

Powered by Google App Engine
This is Rietveld 408576698