| Index: third_party/protobuf/src/google/protobuf/io/coded_stream.h
|
| ===================================================================
|
| --- third_party/protobuf/src/google/protobuf/io/coded_stream.h (revision 216642)
|
| +++ third_party/protobuf/src/google/protobuf/io/coded_stream.h (working copy)
|
| @@ -170,6 +170,9 @@
|
| // successfully and the stream's byte limit.
|
| ~CodedInputStream();
|
|
|
| + // Return true if this CodedInputStream reads from a flat array instead of
|
| + // a ZeroCopyInputStream.
|
| + inline bool IsFlat() const;
|
|
|
| // Skips a number of bytes. Returns false if an underlying read error
|
| // occurs.
|
| @@ -311,8 +314,11 @@
|
|
|
| // Returns the number of bytes left until the nearest limit on the
|
| // stack is hit, or -1 if no limits are in place.
|
| - int BytesUntilLimit();
|
| + int BytesUntilLimit() const;
|
|
|
| + // Returns current position relative to the beginning of the input stream.
|
| + int CurrentPosition() const;
|
| +
|
| // Total Bytes Limit -----------------------------------------------
|
| // To prevent malicious users from sending excessively large messages
|
| // and causing integer overflows or memory exhaustion, CodedInputStream
|
| @@ -327,8 +333,9 @@
|
| // cause integer overflows is 512MB. The default limit is 64MB. Apps
|
| // should set shorter limits if possible. If warning_threshold is not -1,
|
| // a warning will be printed to stderr after warning_threshold bytes are
|
| - // read. An error will always be printed to stderr if the limit is
|
| - // reached.
|
| + // read. For backwards compatibility all negative values get squached to -1,
|
| + // as other negative values might have special internal meanings.
|
| + // An error will always be printed to stderr if the limit is reached.
|
| //
|
| // This is unrelated to PushLimit()/PopLimit().
|
| //
|
| @@ -355,9 +362,10 @@
|
| // messages and groups. CodedInputStream keeps track of this because it
|
| // is the only object that is passed down the stack during parsing.
|
|
|
| - // Sets the maximum recursion depth. The default is 64.
|
| + // Sets the maximum recursion depth. The default is 100.
|
| void SetRecursionLimit(int limit);
|
|
|
| +
|
| // Increments the current recursion depth. Returns true if the depth is
|
| // under the limit, false if it has gone over.
|
| bool IncrementRecursionDepth();
|
| @@ -433,7 +441,8 @@
|
| //
|
| // Note that this feature is ignored when parsing "lite" messages as they do
|
| // not have descriptors.
|
| - void SetExtensionRegistry(DescriptorPool* pool, MessageFactory* factory);
|
| + void SetExtensionRegistry(const DescriptorPool* pool,
|
| + MessageFactory* factory);
|
|
|
| // Get the DescriptorPool set via SetExtensionRegistry(), or NULL if no pool
|
| // has been provided.
|
| @@ -482,6 +491,11 @@
|
| // Maximum number of bytes to read, period. This is unrelated to
|
| // current_limit_. Set using SetTotalBytesLimit().
|
| int total_bytes_limit_;
|
| +
|
| + // If positive/0: Limit for bytes read after which a warning due to size
|
| + // should be logged.
|
| + // If -1: Printing of warning disabled. Can be set by client.
|
| + // If -2: Internal: Limit has been reached, print full size when destructing.
|
| int total_bytes_warning_threshold_;
|
|
|
| // Current recursion depth, controlled by IncrementRecursionDepth() and
|
| @@ -539,7 +553,8 @@
|
| static const int kDefaultTotalBytesLimit = 64 << 20; // 64MB
|
|
|
| static const int kDefaultTotalBytesWarningThreshold = 32 << 20; // 32MB
|
| - static const int kDefaultRecursionLimit = 64;
|
| +
|
| + static int default_recursion_limit_; // 100 by default.
|
| };
|
|
|
| // Class which encodes and writes binary data which is composed of varint-
|
| @@ -891,7 +906,9 @@
|
| // If we are at a limit we know no more bytes can be read. Otherwise, it's
|
| // hard to say without calling Refresh(), and we'd rather not do that.
|
|
|
| - if (buffer_ == buffer_end_ && buffer_size_after_limit_ != 0) {
|
| + if (buffer_ == buffer_end_ &&
|
| + ((buffer_size_after_limit_ != 0) ||
|
| + (total_bytes_read_ == current_limit_))) {
|
| last_tag_ = 0; // Pretend we called ReadTag()...
|
| legitimate_message_end_ = true; // ... and it hit EOF.
|
| return true;
|
| @@ -900,6 +917,10 @@
|
| }
|
| }
|
|
|
| +inline int CodedInputStream::CurrentPosition() const {
|
| + return total_bytes_read_ - (BufferSize() + buffer_size_after_limit_);
|
| +}
|
| +
|
| inline uint8* CodedOutputStream::GetDirectBufferForNBytesAndAdvance(int size) {
|
| if (buffer_size_ < size) {
|
| return NULL;
|
| @@ -1039,7 +1060,7 @@
|
| if (recursion_depth_ > 0) --recursion_depth_;
|
| }
|
|
|
| -inline void CodedInputStream::SetExtensionRegistry(DescriptorPool* pool,
|
| +inline void CodedInputStream::SetExtensionRegistry(const DescriptorPool* pool,
|
| MessageFactory* factory) {
|
| extension_pool_ = pool;
|
| extension_factory_ = factory;
|
| @@ -1071,7 +1092,7 @@
|
| total_bytes_limit_(kDefaultTotalBytesLimit),
|
| total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold),
|
| recursion_depth_(0),
|
| - recursion_limit_(kDefaultRecursionLimit),
|
| + recursion_limit_(default_recursion_limit_),
|
| extension_pool_(NULL),
|
| extension_factory_(NULL) {
|
| // Eagerly Refresh() so buffer space is immediately available.
|
| @@ -1092,17 +1113,15 @@
|
| total_bytes_limit_(kDefaultTotalBytesLimit),
|
| total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold),
|
| recursion_depth_(0),
|
| - recursion_limit_(kDefaultRecursionLimit),
|
| + recursion_limit_(default_recursion_limit_),
|
| extension_pool_(NULL),
|
| extension_factory_(NULL) {
|
| // Note that setting current_limit_ == size is important to prevent some
|
| // code paths from trying to access input_ and segfaulting.
|
| }
|
|
|
| -inline CodedInputStream::~CodedInputStream() {
|
| - if (input_ != NULL) {
|
| - BackUpInputToCurrentPosition();
|
| - }
|
| +inline bool CodedInputStream::IsFlat() const {
|
| + return input_ == NULL;
|
| }
|
|
|
| } // namespace io
|
|
|