diff options
author | Andy Getzendanner <durandal@google.com> | 2022-11-21 21:17:53 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-11-21 21:18:39 -0800 |
commit | 9a7e8e36300c6d89c7f9a2539f7aabf8e0031106 (patch) | |
tree | cbf03dd0ec10bc81451b996df4c9e8437d702ca1 /absl/log/internal/proto.cc | |
parent | d081b629b7c201e701911cfb4e0c99735c21c331 (diff) | |
download | abseil-9a7e8e36300c6d89c7f9a2539f7aabf8e0031106.tar.gz abseil-9a7e8e36300c6d89c7f9a2539f7aabf8e0031106.tar.bz2 abseil-9a7e8e36300c6d89c7f9a2539f7aabf8e0031106.zip |
Zero encoded_remaining when a string field doesn't fit, so that we don't leave partial data in the buffer (all decoders should ignore it anyway) and to be sure that we don't try to put any subsequent operands in either (there shouldn't be enough space).
PiperOrigin-RevId: 490143656
Change-Id: I4d743dd9214013fbd151478ef662d50affd5ff7a
Diffstat (limited to 'absl/log/internal/proto.cc')
-rw-r--r-- | absl/log/internal/proto.cc | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/absl/log/internal/proto.cc b/absl/log/internal/proto.cc index 80d78eed..86c459b0 100644 --- a/absl/log/internal/proto.cc +++ b/absl/log/internal/proto.cc @@ -106,7 +106,8 @@ bool EncodeBytesTruncate(uint64_t tag, absl::Span<const char> value, const uint64_t tag_type = MakeTagType(tag, WireType::kLengthDelimited); const uint64_t tag_type_size = VarintSize(tag_type); uint64_t length = value.size(); - const uint64_t length_size = VarintSize(length); + const uint64_t length_size = + VarintSize(std::min<uint64_t>(length, buf->size())); if (tag_type_size + length_size <= buf->size() && tag_type_size + length_size + value.size() > buf->size()) { value.remove_suffix(tag_type_size + length_size + value.size() - |