Index: third_party/protobuf/src/google/protobuf/arena_test_util.h |
diff --git a/third_party/protobuf/src/google/protobuf/arena_test_util.h b/third_party/protobuf/src/google/protobuf/arena_test_util.h |
index 690cc706ee5f2d029752fe6f1b323130046938e5..8c9f7698c5da6cd2fd25e57cf38afc34ce718e9d 100644 |
--- a/third_party/protobuf/src/google/protobuf/arena_test_util.h |
+++ b/third_party/protobuf/src/google/protobuf/arena_test_util.h |
@@ -31,9 +31,40 @@ |
#ifndef GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__ |
#define GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__ |
+#include <google/protobuf/stubs/logging.h> |
+#include <google/protobuf/stubs/common.h> |
+#include <google/protobuf/arena.h> |
namespace google { |
namespace protobuf { |
+ |
+template <typename T, bool use_arena> |
+void TestParseCorruptedString(const T& message) { |
+ int success_count = 0; |
+ string s = message.SerializeAsString(); |
+ const int kMaxIters = 900; |
+ const int stride = s.size() <= kMaxIters ? 1 : s.size() / kMaxIters; |
+ const int start = stride == 1 || use_arena ? 0 : (stride + 1) / 2; |
+ for (int i = start; i < s.size(); i += stride) { |
+ for (int c = 1 + (i % 17); c < 256; c += 2 * c + (i & 3)) { |
+ s[i] ^= c; |
+ google::protobuf::Arena arena; |
+ T* message = |
+ google::protobuf::Arena::CreateMessage<T>(use_arena ? &arena : NULL); |
+ if (message->ParseFromString(s)) { |
+ ++success_count; |
+ } |
+ if (!use_arena) { |
+ delete message; |
+ } |
+ s[i] ^= c; // Restore s to its original state. |
+ } |
+ } |
+ // This next line is a low bar. But getting through the test without crashing |
+ // due to use-after-free or other bugs is a big part of what we're checking. |
+ GOOGLE_CHECK_GT(success_count, 0); |
+} |
+ |
namespace internal { |
class NoHeapChecker { |