Ignore messages with 0 size
The end of one of our log files has been zeroed out. Throw a warning
when this happens and ignore the rest of the log file.
Change-Id: I38fb794d62ad162ee6e2d8d1a04c3da142e4b572
diff --git a/aos/events/logging/logfile_utils.cc b/aos/events/logging/logfile_utils.cc
index f062ad3..a7238ba 100644
--- a/aos/events/logging/logfile_utils.cc
+++ b/aos/events/logging/logfile_utils.cc
@@ -8,6 +8,7 @@
#include <vector>
+#include "absl/strings/escaping.h"
#include "aos/configuration.h"
#include "aos/events/logging/logger_generated.h"
#include "aos/flatbuffer_merge.h"
@@ -181,6 +182,15 @@
const size_t data_size =
flatbuffers::GetPrefixedSize(data_.data() + consumed_data_) +
sizeof(flatbuffers::uoffset_t);
+ if (data_size == sizeof(flatbuffers::uoffset_t)) {
+ LOG(ERROR) << "Size of data is zero. Log file end is corrupted, skipping.";
+ LOG(ERROR) << " Rest of log file is "
+ << absl::BytesToHexString(std::string_view(
+ reinterpret_cast<const char *>(data_.data() +
+ consumed_data_),
+ data_.size() - consumed_data_));
+ return absl::Span<const uint8_t>();
+ }
while (data_.size() < consumed_data_ + data_size) {
if (!ReadBlock()) {
return absl::Span<const uint8_t>();