Operating System / Platform => :Ubuntu 20.04 amd64:
Compiler => :any:
Detailed description
In file opencv_contrib-4.6.0/modules/wechat_qrcode/src/zxing/common/binarizer/global_histogram_binarizer.cpp there is global shared state in line 18, which causing segfault in case of multithreading.
Steps to reproduce
Flaky to reproduce. In my case, one of 4 test runs with 8 threads simultaneously processing same image with same WeChatQRCode instance for around 15 sec cause segfault.
Cant provide image due to NDA. Any small image like 120 * 50 should be fine, I guess.
{
auto index = 0;
auto image = mats[index];
bool finish = false;
std::atomic_uint32_t counter;
std::vector<std::thread> threads;
cv::WeChatQRCode decoder;
for (size_t i = 0; i < 8; ++i) {
threads.emplace_back([&] {
while (!finish) {
decoder.detectAndDecode(image, {});
auto val = counter++;
if (val % 100 == 0) {
std::cout << val << std::endl;
}
}
});
}
while (counter < 7000) {
sleep(1);
}
finish = true;
for (auto& t : threads) {
t.join();
}
}
How to fix:
Wipe out this shared variable and initialize luminances var with default ctor. Also add check for !luminances in line 29.
Issue submission checklist
[x] I report the issue, it's not a question
[x] I checked the problem with documentation, FAQ, open issues,
forum.opencv.org, Stack Overflow, etc and have not found any solution
[x] I updated to the latest OpenCV version and the issue is still there
[x] There is reproducer code and related data files: videos, images, onnx, etc
I also met this problem. The Implement of shared ArrayRef is not safe in multithreads. The Solution mentioned by @nxt007 Is Right. The global Shared ArrayRef EMPTY should not used In multithread.
System information (version)
Detailed description
In file
opencv_contrib-4.6.0/modules/wechat_qrcode/src/zxing/common/binarizer/global_histogram_binarizer.cpp
there is global shared state in line 18, which causing segfault in case of multithreading.Steps to reproduce
Flaky to reproduce. In my case, one of 4 test runs with 8 threads simultaneously processing same image with same WeChatQRCode instance for around 15 sec cause segfault.
Cant provide image due to NDA. Any small image like 120 * 50 should be fine, I guess.
How to fix:
Wipe out this shared variable and initialize
luminances
var with default ctor. Also add check for!luminances
in line 29.Issue submission checklist