From 378a13ecdc54b8208fdd209350794b692e2b6d90 Mon Sep 17 00:00:00 2001 From: Sergey Alexandrov Date: Sat, 18 Jan 2014 11:56:50 +0100 Subject: [PATCH 1/2] Fix out-of-bound array access in copyPointCloud() --- common/include/pcl/common/impl/io.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/include/pcl/common/impl/io.hpp b/common/include/pcl/common/impl/io.hpp index c2ea0280e93..a728f704394 100644 --- a/common/include/pcl/common/impl/io.hpp +++ b/common/include/pcl/common/impl/io.hpp @@ -293,7 +293,7 @@ pcl::copyPointCloud (const pcl::PointCloud &cloud_in, // Copy the rest pcl::for_each_type (pcl::NdConcatenateFunctor (cloud_in.points[indices[i]], cloud_out.points[i])); // Copy RGB<->RGBA - memcpy (reinterpret_cast (&cloud_out.points[indices[i]]) + fields_out[rgb_idx_out].offset, reinterpret_cast (&cloud_in.points[i]) + fields_in[rgb_idx_in].offset, field_size_in); + memcpy (reinterpret_cast (&cloud_out.points[i]) + fields_out[rgb_idx_out].offset, reinterpret_cast (&cloud_in.points[indices[i]]) + fields_in[rgb_idx_in].offset, field_size_in); } return; } @@ -470,7 +470,7 @@ pcl::copyPointCloud (const pcl::PointCloud &cloud_in, // Copy the rest pcl::for_each_type (pcl::NdConcatenateFunctor (cloud_in.points[indices.indices[i]], cloud_out.points[i])); // Copy RGB<->RGBA - memcpy (reinterpret_cast (&cloud_out.points[indices.indices[i]]) + fields_out[rgb_idx_out].offset, reinterpret_cast (&cloud_in.points[i]) + fields_in[rgb_idx_in].offset, field_size_in); + memcpy (reinterpret_cast (&cloud_out.points[i]) + fields_out[rgb_idx_out].offset, reinterpret_cast (&cloud_in.points[indices.indices[i]]) + fields_in[rgb_idx_in].offset, field_size_in); } return; } From e01aec862786d882a4b8d15dde2d5416ab3535fb Mon Sep 17 00:00:00 2001 From: Sergey Alexandrov Date: Tue, 21 Jan 2014 00:29:37 +0100 Subject: [PATCH 2/2] Add a test case for `copyPointCloud()` bug --- test/common/test_io.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/common/test_io.cpp b/test/common/test_io.cpp index 091f57e03c3..2e3c1dce51c 100644 --- a/test/common/test_io.cpp +++ b/test/common/test_io.cpp @@ -379,6 +379,27 @@ TEST (PCL, concatenatePointCloud) } } +TEST (PCL, CopyPointCloudWithIndicesAndRGBToRGBA) +{ + CloudXYZRGB cloud_xyz_rgb; + CloudXYZRGBA cloud_xyz_rgba (5, 1, pt_xyz_rgba); + + std::vector indices; + indices.push_back (2); + indices.push_back (3); + + pcl::copyPointCloud (cloud_xyz_rgba, indices, cloud_xyz_rgb); + + EXPECT_EQ (indices.size (), cloud_xyz_rgb.size ()); + for (size_t i = 0; i < indices.size (); ++i) + { + EXPECT_FLOAT_EQ (cloud_xyz_rgb[i].x, cloud_xyz_rgba[indices[i]].x); + EXPECT_FLOAT_EQ (cloud_xyz_rgb[i].y, cloud_xyz_rgba[indices[i]].y); + EXPECT_FLOAT_EQ (cloud_xyz_rgb[i].z, cloud_xyz_rgba[indices[i]].z); + EXPECT_EQ (cloud_xyz_rgb[i].rgba, cloud_xyz_rgba[indices[i]].rgba); + } +} + /* ---[ */ int main (int argc, char** argv)