Resize IPC input buffer to fit the next message.
Sometimes we can get IPC message size from its header. In those cases
we resize IPC::ChannelReader' overflow buffer to fit the entire message
to avoid growing / reallocating it as we receive message's data.
BUG=529940
Review URL: https://codereview.chromium.org/1345353004
Cr-Commit-Position: refs/heads/master@{#351586}
diff --git a/base/pickle.h b/base/pickle.h
index b6ec116..22b8055 100644
--- a/base/pickle.h
+++ b/base/pickle.h
@@ -271,6 +271,18 @@
const char* range_start,
const char* range_end);
+ // Parse pickle header and return total size of the pickle. Data range
+ // doesn't need to contain entire pickle.
+ // Returns true if pickle header was found and parsed. Callers must check
+ // returned |pickle_size| for sanity (against maximum message size, etc).
+ // NOTE: when function successfully parses a header, but encounters an
+ // overflow during pickle size calculation, it sets |pickle_size| to the
+ // maximum size_t value and returns true.
+ static bool PeekNext(size_t header_size,
+ const char* range_start,
+ const char* range_end,
+ size_t* pickle_size);
+
// The allocation granularity of the payload.
static const int kPayloadUnit;
@@ -298,6 +310,8 @@
FRIEND_TEST_ALL_PREFIXES(PickleTest, DeepCopyResize);
FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize);
+ FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext);
+ FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow);
FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext);
FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader);
FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow);