From 0786b52c2ea0d168fcc18a0a90db1273c4cfc711 Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Mon, 19 Jul 2021 12:09:58 +0200 Subject: [PATCH] Stop parsing if current message length is bigger than buffer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If allow_incomplete_logs_ is false and the current message length is bigger than the remaining buffer, this CL returns an error status to the client. Bug: None Change-Id: Idcacda9f42429416da3272651621b8d5936fc69e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/225545 Reviewed-by: Björn Terelius Reviewed-by: Elad Alon Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#34500} --- logging/rtc_event_log/rtc_event_log_parser.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/logging/rtc_event_log/rtc_event_log_parser.cc b/logging/rtc_event_log/rtc_event_log_parser.cc index 08fb9408c1..91df18b226 100644 --- a/logging/rtc_event_log/rtc_event_log_parser.cc +++ b/logging/rtc_event_log/rtc_event_log_parser.cc @@ -1311,12 +1311,17 @@ ParsedRtcEventLog::ParseStatus ParsedRtcEventLog::ParseStreamInternal( } if (message_length > s.size()) { - RTC_LOG(LS_WARNING) << "Protobuf message length is too large."; + RTC_LOG(LS_WARNING) << "Protobuf message length is larger than the " + "remaining bytes in the proto."; RTC_PARSE_WARN_AND_RETURN_SUCCESS_IF(allow_incomplete_logs_, kIncompleteLogError); - RTC_PARSE_CHECK_OR_RETURN_LE(message_length, kMaxEventSize); + return ParseStatus::Error( + "Incomplete message: the length of the next message is larger than " + "the remaining bytes in the proto", + __FILE__, __LINE__); } + RTC_PARSE_CHECK_OR_RETURN_LE(message_length, kMaxEventSize); // Skip forward to the start of the next event. s = s.substr(message_length); size_t total_event_size = event_start.size() - s.size();