Skip to content

Commit 229cd72

Browse files
deni64kalalek
authored andcommitted
Merge pull request #2309 from deni64k:master
Fix memory corruption in RgbdPlane * Fix memory corruption * Use divUp instead of explicit rounding up integer division * rgbd: add test
1 parent 8fde8d7 commit 229cd72

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

modules/rgbd/src/plane.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,8 @@ class InlierFinder
584584
plane = Ptr<PlaneBase>(new PlaneABC(plane_grid.m_(y, x), n, (int)index_plane,
585585
(float)sensor_error_a_, (float)sensor_error_b_, (float)sensor_error_c_));
586586

587-
Mat_<unsigned char> plane_mask = Mat_<unsigned char>::zeros(points3d.rows / block_size_,
588-
points3d.cols / block_size_);
587+
Mat_<unsigned char> plane_mask = Mat_<unsigned char>::zeros(divUp(points3d.rows, block_size_),
588+
divUp(points3d.cols, block_size_));
589589
std::set<TileQueue::PlaneTile> neighboring_tiles;
590590
neighboring_tiles.insert(front_tile);
591591
plane_queue.remove(front_tile.y_, front_tile.x_);

modules/rgbd/test/test_normal.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,15 @@ TEST(Rgbd_Plane, compute)
470470
test.safe_run();
471471
}
472472

473+
TEST(Rgbd_Plane, regression_2309_valgrind_check)
474+
{
475+
Mat points(640, 480, CV_32FC3, Scalar::all(0));
476+
rgbd::RgbdPlane plane_detector;
477+
plane_detector.setBlockSize(9); // Note, 640%9 is 1 and 480%9 is 3
478+
479+
Mat mask;
480+
std::vector<cv::Vec4f> planes;
481+
plane_detector(points, mask, planes); // Will corrupt memory; valgrind gets triggered
482+
}
483+
473484
}} // namespace

0 commit comments

Comments
 (0)