From 2443e7545fc7d49007d90e5056eaff5ac3eea560 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Fri, 31 Jul 2020 16:56:59 +0300 Subject: [PATCH] [tracking] Crash fix in case of Protocol::DecodeHeader({}). --- tracking/protocol.cpp | 10 +++++++++- tracking/protocol.hpp | 1 + tracking/pytracking/bindings.cpp | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tracking/protocol.cpp b/tracking/protocol.cpp index 984ede9f33..9308c5b10a 100644 --- a/tracking/protocol.cpp +++ b/tracking/protocol.cpp @@ -23,6 +23,7 @@ vector CreateDataPacketImpl(Container const & points, uint32_t version = tracking::Protocol::Encoder::kLatestVersion; switch (type) { + case tracking::Protocol::PacketType::Error: ASSERT(false, ("Error DATA packet.")); return {}; case tracking::Protocol::PacketType::DataV0: version = 0; break; case tracking::Protocol::PacketType::DataV1: version = 1; break; case tracking::Protocol::PacketType::AuthV0: ASSERT(false, ("Not a DATA packet.")); break; @@ -78,7 +79,11 @@ vector Protocol::CreateDataPacket(DataElementsVec const & points, Packe // static pair Protocol::DecodeHeader(vector const & data) { - ASSERT_GREATER_OR_EQUAL(data.size(), sizeof(uint32_t /* header */), ()); + if (data.size() < sizeof(uint32_t /* header */)) + { + LOG(LWARNING, ("Header size is too small", data.size(), sizeof(uint32_t /* header */))); + return make_pair(PacketType::Error, data.size()); + } uint32_t size = (*reinterpret_cast(data.data())) & 0xFFFFFF00; if (!IsBigEndianMacroBased()) @@ -92,6 +97,7 @@ string Protocol::DecodeAuthPacket(Protocol::PacketType type, vector con { switch (type) { + case Protocol::PacketType::Error: ASSERT(false, ("Error AUTH packet.")); break; case Protocol::PacketType::AuthV0: return string(begin(data), end(data)); case Protocol::PacketType::DataV0: case Protocol::PacketType::DataV1: ASSERT(false, ("Not an AUTH packet.")); break; @@ -109,6 +115,7 @@ Protocol::DataElementsVec Protocol::DecodeDataPacket(PacketType type, vector("PacketType") + .value("Error", Protocol::PacketType::Error) .value("AuthV0", Protocol::PacketType::AuthV0) .value("DataV0", Protocol::PacketType::DataV0) .value("DataV1", Protocol::PacketType::DataV1)