mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
69
tracking/tracking_fuzz_tests/tracking_fuzz_tests.cpp
Normal file
69
tracking/tracking_fuzz_tests/tracking_fuzz_tests.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "tracking/protocol.hpp"
|
||||
|
||||
#include "coding/traffic.hpp"
|
||||
|
||||
#include "geometry/latlon.hpp"
|
||||
|
||||
#include "base/logging.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
using namespace coding;
|
||||
using namespace tracking;
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T>
|
||||
T PopType(std::vector<uint8_t> & data)
|
||||
{
|
||||
T t{};
|
||||
if (data.empty())
|
||||
return t;
|
||||
|
||||
if (data.size() < sizeof(T))
|
||||
{
|
||||
data.clear();
|
||||
return t;
|
||||
}
|
||||
|
||||
t = *reinterpret_cast<T *>(data.data());
|
||||
data.erase(data.begin(), std::next(data.begin(), sizeof(T)));
|
||||
return t;
|
||||
}
|
||||
|
||||
TrafficGPSEncoder::DataPoint PopDataPoint(std::vector<uint8_t> & data)
|
||||
{
|
||||
auto const timestamp = PopType<uint64_t>(data);
|
||||
auto const lat = PopType<double>(data);
|
||||
auto const lon = PopType<double>(data);
|
||||
auto const traffic = PopType<uint8_t>(data);
|
||||
return TrafficGPSEncoder::DataPoint(timestamp, ms::LatLon(lat, lon), traffic);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const * data, size_t size)
|
||||
{
|
||||
base::ScopedLogLevelChanger scopedLogLevelChanger(base::LCRITICAL);
|
||||
|
||||
std::vector<uint8_t> const dataVec(data, data + size);
|
||||
|
||||
auto dataVecToConv = dataVec;
|
||||
Protocol::DataElementsVec dataElementsVec;
|
||||
while (!dataVecToConv.empty())
|
||||
dataElementsVec.push_back(PopDataPoint(dataVecToConv));
|
||||
Protocol::DataElementsCirc dataElementsCirc(dataElementsVec.cbegin(), dataElementsVec.cend());
|
||||
|
||||
Protocol::DecodeHeader(dataVec);
|
||||
for (auto const type : {Protocol::PacketType::Error, Protocol::PacketType::AuthV0,
|
||||
Protocol::PacketType::DataV0, Protocol::PacketType::DataV1})
|
||||
{
|
||||
Protocol::CreateDataPacket(dataElementsVec, type);
|
||||
Protocol::CreateDataPacket(dataElementsCirc, type);
|
||||
Protocol::DecodeAuthPacket(type, dataVec);
|
||||
Protocol::DecodeDataPacket(type, dataVec);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user