PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.89k stars 4.61k forks source link

[RangeImage] Segmentation Fault in RangeImage::createFromPointCloud #5366

Closed CaptainXX closed 2 years ago

CaptainXX commented 2 years ago

Describe the bug

Api RangImage::createFromPointCloud will cause segmentation fault when there is a zero point (x, y, z = 0, 0, 0) in the pointcloud. The Library is built from the newest release source code.

Context

I was trying to generate and visualize the range view image from pointcloud with the pcl tutorial code. It was ok when using the generated pointcloud, but when I was trying to run it with a pcd file from DAIR-V2X-I Dataset, a segmentaion fault happened.

Then I tried to run it with gdb, the stack showed pcl::RangeImage::getImagePoint caused this segmentation fault.

(gdb) r
Starting program: /home/bw/bg_substraction/build/pcl_inspector ./test-ascii.pcd
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7f88656 in pcl::RangeImage::getImagePoint(Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, float&, float&, float&) const () from /usr/local/lib/libpcl_visualization.so.1.12
(gdb) bt
#0  0x00007ffff7f88656 in pcl::RangeImage::getImagePoint(Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, float&, float&, float&) const () from /usr/local/lib/libpcl_visualization.so.1.12
#1  0x00005555555637ec in void pcl::RangeImage::doZBuffer<pcl::PointCloud<pcl::PointXYZ> >(pcl::PointCloud<pcl::PointXYZ> const&, float, float, int&, int&, int&, int&) ()
#2  0x000055555556081a in void pcl::RangeImage::createFromPointCloud<pcl::PointCloud<pcl::PointXYZ> >(pcl::PointCloud<pcl::PointXYZ> const&, float, float, float, float, Eigen::Transform<float, 3, 2, 0> const&, pcl::RangeImage::CoordinateFrame, float, float, int) ()
#3  0x000055555555b456 in main ()
(gdb) 

And I found that the segementation fault always happened at getting the last point. It showed to be a row with (x, y, z, intensity) = (0, 0, 0, 0). Then I deleted it, and the program worked again.

Expected behavior

A RangImage object can be successfully initialized from pointcloud.

Current Behavior

Segmentation fault in situation described above.

To Reproduce

Simply add a full zero row in the data field of the pcd file. I tested a few of files, and all of them cloud reproduce this problem.

A segmentation fault generator pcd file like this:

image-20220802172756546

Run it with the tutorial code:

1659432830

Your Environment (please complete the following information):

Possible Solution

I found the patch in #5149, but it did not work.

mvieth commented 2 years ago

Please try compiling the latest PCL master branch and check if the problem still exists (remember to first delete the currently installed PCL and also recompile your own code)

CaptainXX commented 2 years ago

It's solved in master branch! Sorry for not testing it.

Hope there will be a new release, because most of people may not clone and build from master branch.

@mvieth Thanks a lot for your reply!

mvieth commented 2 years ago

You're welcome. Yes, we will consider doing a release in the upcoming months