vectr-ucla / direct_lidar_inertial_odometry

[IEEE ICRA'23] A new lightweight LiDAR-inertial odometry algorithm with a novel coarse-to-fine approach in constructing continuous-time trajectories for precise motion correction.
MIT License
521 stars 101 forks source link

Odom node crashes when unstructured pointcloud with width=0 is given, due to division by zero error #40

Open epsilam opened 2 months ago

epsilam commented 2 months ago

When dlio::OdomNode::publishCloud(published_cloud, T_cloud) is called with published_cloud having a width of 0, the odometry node will crash due to a propagated division by zero error. This happens because publishCloud calls the following method with the copy_all_fields argument set to true (by default):

pcl::transformPointCloud (const pcl::PointCloud<PointT> &cloud_in,
                     pcl::PointCloud<PointT> &cloud_out,
                     const Eigen::Matrix<Scalar, 4, 4> &transform,
                     bool copy_all_fields)
{
...
  if (copy_all_fields)
        cloud_out.assign (cloud_in.begin (), cloud_in.end (), cloud_in.width);
      else
        cloud_out.resize (cloud_in.width, cloud_in.height);
...
}

This method furthermore calls the following assign method:

template <class InputIterator>
inline void
assign(InputIterator first, InputIterator last, index_t new_width)
{
  points.assign(std::move(first), std::move(last));
  width = new_width;
  height = size() / width;
  if (width * height != size()) {
    PCL_WARN("Mismatch in assignment. Requested width (%zu) doesn't divide "
             "provided size (%zu) cleanly. Setting height to 1\n",
             static_cast<std::size_t>(width),
             static_cast<std::size_t>(size()));
    width = size();
    height = 1;
  }
}

The division by width results in an uncaught division by zero error. This is easily fixed by calling pcl::transformPointCloud with copy_all_fields set to false.