aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/stubs/structurally_valid_unittest.cc
diff options
context:
space:
mode:
authorGravatar kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-12-11 03:49:28 +0000
committerGravatar kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-12-11 03:49:28 +0000
commitb221008884cec52232b2c292f743cad0ed4d3dee (patch)
tree43bbfce99e41c5cecf83f9497f9939a41198791e /src/google/protobuf/stubs/structurally_valid_unittest.cc
parentde747794544996f460c6cf07e0e5c3b7757efc92 (diff)
Fix UTF-8 validity checks to not do unaligned reads.
Diffstat (limited to 'src/google/protobuf/stubs/structurally_valid_unittest.cc')
-rw-r--r--src/google/protobuf/stubs/structurally_valid_unittest.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/google/protobuf/stubs/structurally_valid_unittest.cc b/src/google/protobuf/stubs/structurally_valid_unittest.cc
index 22825516..90888885 100644
--- a/src/google/protobuf/stubs/structurally_valid_unittest.cc
+++ b/src/google/protobuf/stubs/structurally_valid_unittest.cc
@@ -13,15 +13,25 @@ TEST(StructurallyValidTest, ValidUTF8String) {
// On GCC, this string can be written as:
// "abcd 1234 - \u2014\u2013\u2212"
// MSVC seems to interpret \u differently.
- string valid_str("abcd 1234 - \342\200\224\342\200\223\342\210\222");
+ string valid_str("abcd 1234 - \342\200\224\342\200\223\342\210\222 - xyz789");
EXPECT_TRUE(IsStructurallyValidUTF8(valid_str.data(),
valid_str.size()));
+ // Additional check for pointer alignment
+ for (int i = 1; i < 8; ++i) {
+ EXPECT_TRUE(IsStructurallyValidUTF8(valid_str.data() + i,
+ valid_str.size() - i));
+ }
}
TEST(StructurallyValidTest, InvalidUTF8String) {
- string invalid_str("\xA0\xB0");
+ const string invalid_str("abcd\xA0\xB0\xA0\xB0\xA0\xB0 - xyz789");
EXPECT_FALSE(IsStructurallyValidUTF8(invalid_str.data(),
invalid_str.size()));
+ // Additional check for pointer alignment
+ for (int i = 1; i < 8; ++i) {
+ EXPECT_FALSE(IsStructurallyValidUTF8(invalid_str.data() + i,
+ invalid_str.size() - i));
+ }
}
} // namespace