From fcdaaabf7c7e8c00e67dc6f402c098339a83554e Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Thu, 19 Oct 2023 22:42:11 +0200 Subject: [PATCH] Unconditionally create SuperScale in BarcodeDetector to avoid null deref This pointer is called unconditionally in BarcodeImpl::initDecode assuming the size of the image is outside the specified bounds. This seems to not cause problems on optimized builds, I assume because the optimizer sees through the processImageScale call to see that it can be reduced to a resize call. Leaving it as is relies on undefined behavior. This was the least invasive change I could make, however, it might be worthwhile to pull up the logic for a resize so that a SuperScale does not need to be allocated, which seems to be the most common case. --- modules/objdetect/src/barcode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/objdetect/src/barcode.cpp b/modules/objdetect/src/barcode.cpp index 549ea84a0a..e0c7d9cb57 100644 --- a/modules/objdetect/src/barcode.cpp +++ b/modules/objdetect/src/barcode.cpp @@ -343,11 +343,11 @@ BarcodeDetector::BarcodeDetector(const string &prototxt_path, const string &mode { Ptr p_ = new BarcodeImpl(); p = p_; + p_->sr = make_shared(); if (!prototxt_path.empty() && !model_path.empty()) { CV_Assert(utils::fs::exists(prototxt_path)); CV_Assert(utils::fs::exists(model_path)); - p_->sr = make_shared(); int res = p_->sr->init(prototxt_path, model_path); CV_Assert(res == 0); p_->use_nn_sr = true;