fix: a merged segment lost the scan it was built from, so pointAt read past the end
The constructor mergeLines uses took only the fitted parameters and the ray indices, leaving c_data_ and r_data_ default-constructed. pointAt indexes r_data_.xs directly, so asking a merged segment where one of its own rays is read past the end of an empty vector. Two callers already do exactly that. The reflective-tape check walks the ray span of a wing and reads each point; the arc matcher gathers the points of adjacent segments to fit a circle to them. The arc matcher is how it surfaced - it segfaulted, and AddressSanitizer put it on line.cpp:58. It stayed hidden because mergeLines almost never fires with the default parameters: a gap wide enough to split at is already wider than max_line_gap, which is the gate merging has to pass. That is the merge gate working as intended, and it is also why this could not be reached from a synthesized scene - a scene-based test here would guard nothing, so the regression test builds a merged Line directly instead. The constructor now takes the scan data, like the other one. A merged segment is still built from the same scan, so there was never a reason for it to lose it, and a consumer cannot tell a merged segment from a fresh one - the invariant has to be that every segment answers for every ray it supports. pointAt also bounds-checks now and returns NaN for a ray it does not carry. That is a second line of defence, not the fix: every caller already has to reject non-finite points because a real scan contains them, so a future constructor that forgets the data degrades instead of reading out of bounds.
This commit is contained in:
@@ -42,10 +42,17 @@ public:
|
||||
Line(const CachedData& c_data, const RangeData& r_data, const LineExtractionParams& params,
|
||||
std::vector<unsigned int> indices);
|
||||
|
||||
/// @brief Build from already-known parameters. Used when two lines merge into one.
|
||||
Line(double angle, double radius, const std::array<double, 4>& covariance,
|
||||
const std::array<double, 2>& start, const std::array<double, 2>& end,
|
||||
const std::vector<unsigned int>& indices);
|
||||
/**
|
||||
* @brief Build from already-known parameters. Used when two lines merge into one.
|
||||
*
|
||||
* Takes the scan data as well, even though the fit is already done and none of it is needed to
|
||||
* describe the line. It is needed to describe the RAYS: a merged segment still answers @ref
|
||||
* pointAt for every ray it supports, and a consumer cannot tell a merged segment from a fresh
|
||||
* one. Leaving these empty is how @ref pointAt was made to read past the end of an empty vector.
|
||||
*/
|
||||
Line(const CachedData& c_data, const RangeData& r_data, double angle, double radius,
|
||||
const std::array<double, 4>& covariance, const std::array<double, 2>& start,
|
||||
const std::array<double, 2>& end, const std::vector<unsigned int>& indices);
|
||||
|
||||
double getAngle() const
|
||||
{
|
||||
@@ -102,6 +109,10 @@ public:
|
||||
*
|
||||
* @warning @p index is a RAY number, the same numbering @ref getIndices returns. It is not a
|
||||
* position within this segment's support.
|
||||
*
|
||||
* @return {NaN, NaN} if the segment does not carry the ray. Callers already have to reject
|
||||
* non-finite points because a scan contains them, so a guard that reads out of bounds
|
||||
* instead would be caught by nobody.
|
||||
*/
|
||||
std::array<double, 2> pointAt(unsigned int index) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user