Skip to content

Commit

Permalink
Merge pull request PointCloudLibrary#453 from taketwo/fix-copy-point-…
Browse files Browse the repository at this point in the history
…cloud

Fix out-of-bound array access in `copyPointCloud()`
  • Loading branch information
rbrusu committed Jan 21, 2014
2 parents 01e5fab + e01aec8 commit 1bd2020
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions common/include/pcl/common/impl/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ pcl::copyPointCloud (const pcl::PointCloud<PointInT> &cloud_in,
// Copy the rest
pcl::for_each_type<FieldList> (pcl::NdConcatenateFunctor <PointInT, PointOutT> (cloud_in.points[indices[i]], cloud_out.points[i]));
// Copy RGB<->RGBA
memcpy (reinterpret_cast<char*> (&cloud_out.points[indices[i]]) + fields_out[rgb_idx_out].offset, reinterpret_cast<const char*> (&cloud_in.points[i]) + fields_in[rgb_idx_in].offset, field_size_in);
memcpy (reinterpret_cast<char*> (&cloud_out.points[i]) + fields_out[rgb_idx_out].offset, reinterpret_cast<const char*> (&cloud_in.points[indices[i]]) + fields_in[rgb_idx_in].offset, field_size_in);
}
return;
}
Expand Down Expand Up @@ -470,7 +470,7 @@ pcl::copyPointCloud (const pcl::PointCloud<PointInT> &cloud_in,
// Copy the rest
pcl::for_each_type<FieldList> (pcl::NdConcatenateFunctor <PointInT, PointOutT> (cloud_in.points[indices.indices[i]], cloud_out.points[i]));
// Copy RGB<->RGBA
memcpy (reinterpret_cast<char*> (&cloud_out.points[indices.indices[i]]) + fields_out[rgb_idx_out].offset, reinterpret_cast<const char*> (&cloud_in.points[i]) + fields_in[rgb_idx_in].offset, field_size_in);
memcpy (reinterpret_cast<char*> (&cloud_out.points[i]) + fields_out[rgb_idx_out].offset, reinterpret_cast<const char*> (&cloud_in.points[indices.indices[i]]) + fields_in[rgb_idx_in].offset, field_size_in);
}
return;
}
Expand Down
21 changes: 21 additions & 0 deletions test/common/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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)
Expand Down

0 comments on commit 1bd2020

Please sign in to comment.