System information (version)
- OpenCV => 4.1.0
- Operating System / Platform => Android
- Compiler => GCC
Detailed description
ConnectedComponents will systematically crash due to memory problem (invalid address or address of corrupt block 0xb93180f8 passed to dlfree) when running parallel Grana algorithm on some image sizes on Android. I could reproduce with the following code:
Steps to reproduce
auto darkMask = cv::Mat();
darkMask.create(31, 87, CV_8U);
darkMask = 0;
auto labels = cv::Mat();
auto stats = cv::Mat();
auto centroids = cv::Mat();
const auto nbComponents = cv::connectedComponentsWithStats(darkMask, labels, stats, centroids, 8, CV_32S, cv::CCL_GRANA);
I narrowed down to the following code connectedcomponents.cpp line 2563:
for (int i = 0; i < h; i = chunksSizeAndLabels[i]){
flattenL(P, LabelT((i + 1) / 2) * LabelT((w + 1) / 2) + 1, chunksSizeAndLabels[i + 1], nLabels);
}
Variable i ends up with value h-1, whereas the code accesses chunksSizeAndLabels[i + 1] and chunksSizeAndLabels allocated size is h elements. We access out of bounds element chunksSizeAndLabels[h].
I'm not sure how to fix the code properly.
System information (version)
Detailed description
ConnectedComponents will systematically crash due to memory problem (invalid address or address of corrupt block 0xb93180f8 passed to dlfree) when running parallel Grana algorithm on some image sizes on Android. I could reproduce with the following code:
Steps to reproduce
I narrowed down to the following code connectedcomponents.cpp line 2563:
Variable
iends up with valueh-1, whereas the code accesseschunksSizeAndLabels[i + 1]andchunksSizeAndLabelsallocated size ishelements. We access out of bounds elementchunksSizeAndLabels[h].I'm not sure how to fix the code properly.