Skip to content

ConnectedComponents crash with Parallel Grana algorithm #14955

@arnaudbrejeon

Description

@arnaudbrejeon
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions