Use-after-move / empty vector dereference in MergePoints (libs/drape_frontend/read_metaline_task.cpp)
Author: HugeCreated Oct 1, 2026Updated Oct 1, 2026
Description of the Issue
In libs/drape_frontend/read_metaline_task.cpp, MergePoints() can dereference an iterator on an empty vector, leading to undefined behavior / crash (SIGSEGV) whenever a metaline contains duplicate FeatureIDs (e.g. [A, B, A]).
Location
libs/drape_frontend/read_metaline_task.cpp (lines ~103–118 in MergePoints):
for (auto const & f : featuresOrder)
{
auto const it = points.find(f);
ASSERT(it != points.cend(), ());
if (!result.empty())
{
auto iBeg = it->second.begin();
if (result.back().EqualDxDy(*iBeg, kMwmPointAccuracy))
++iBeg;
result.insert(result.end(), iBeg, it->second.end());
}
else
result = std::move(it->second);
}Mechanism / Root Cause
- No deduplication in reader:
ReadMetalinesFromFile()parsesMetalineData::m_featuresdirectly from varints without checking for duplicates:auto const fid = ReadVarInt<int32_t>(src); FeatureID const featureId(mwmId, static_cast<uint32_t>(std::abs(fid))); data.m_features.emplace_back(featureId); - Move on first occurrence: In
MergePoints(), ifpoints.size() > 1(bypassing the single-feature early return), the loop starts withresult.empty() == true. The first feature infeaturesOrder(e.g.A) falls into theelsebranch:This moves the vector contents intoresult = std::move(it->second);result, leavingpoints[A]empty (it->second.empty() == true). - Empty dereference on subsequent occurrence: When feature
Ais encountered again later infeaturesOrder(e.g. withfeaturesOrder = [A, B, A]):!result.empty()is now true.auto iBeg = it->second.begin();is obtained. Sinceit->secondis empty,iBeg == it->second.end().result.back().EqualDxDy(*iBeg, kMwmPointAccuracy)unconditionally dereferences*iBeg.- Dereferencing
end()of an empty vector is undefined behavior, causing an invalid memory read / crash.
Suggested Fix
At minimum, guard against an empty vector or check iBeg != it->second.end() before dereferencing:
if (!result.empty())
{
if (it->second.empty())
continue;
auto iBeg = it->second.begin();
if (result.back().EqualDxDy(*iBeg, kMwmPointAccuracy))
++iBeg;
result.insert(result.end(), iBeg, it->second.end());
}
else
result = std::move(it->second);Or ensure deduplication / consistency when populating m_features in ReadMetalinesFromFile().
Note: Due to current time constraints, I will not be able to prepare a repro test case or submit a PR before next week. Opening this report early so the team is aware of the issue.
Source: organicmaps/organicmaps