From 423bc515e5387a255105cf402c7b547d0703e105 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 9 Dec 2022 15:06:08 +0300 Subject: [PATCH] Integer underflow fix for morphologyEx in Carotene (arm). --- 3rdparty/carotene/hal/tegra_hal.hpp | 4 ++-- modules/imgproc/test/test_filter.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/3rdparty/carotene/hal/tegra_hal.hpp b/3rdparty/carotene/hal/tegra_hal.hpp index c2ae0c0..ce8fa90 100644 --- a/3rdparty/carotene/hal/tegra_hal.hpp +++ b/3rdparty/carotene/hal/tegra_hal.hpp @@ -1296,13 +1296,13 @@ struct MorphCtx CAROTENE_NS::BORDER_MODE border; uchar borderValues[4]; }; -inline int TEGRA_MORPHINIT(cvhalFilter2D **context, int operation, int src_type, int dst_type, int, int, +inline int TEGRA_MORPHINIT(cvhalFilter2D **context, int operation, int src_type, int dst_type, int width, int height, int kernel_type, uchar *kernel_data, size_t kernel_step, int kernel_width, int kernel_height, int anchor_x, int anchor_y, int borderType, const double borderValue[4], int iterations, bool allowSubmatrix, bool allowInplace) { if(!context || !kernel_data || src_type != dst_type || CV_MAT_DEPTH(src_type) != CV_8U || src_type < 0 || (src_type >> CV_CN_SHIFT) > 3 || - + width < kernel_width || height < kernel_height || allowSubmatrix || allowInplace || iterations != 1 || !CAROTENE_NS::isSupportedConfiguration()) return CV_HAL_ERROR_NOT_IMPLEMENTED; diff --git a/modules/imgproc/test/test_filter.cpp b/modules/imgproc/test/test_filter.cpp index 6de6cf4..b0b4fdf 100644 --- a/modules/imgproc/test/test_filter.cpp +++ b/modules/imgproc/test/test_filter.cpp @@ -2366,5 +2366,18 @@ TEST(Imgproc_GaussianBlur, regression_11303) EXPECT_LE(cv::norm(src, dst, NORM_L2), 1e-3); } +TEST(Imgproc, morphologyEx_small_input_22893) +{ + char input_data[] = {1, 2, 3, 4}; + char gold_data[] = {2, 3, 4, 4}; + cv::Mat img(1, 4, CV_8UC1, input_data); + cv::Mat gold(1, 4, CV_8UC1, gold_data); + + cv::Mat kernel = getStructuringElement(cv::MORPH_RECT, cv::Size(4,4)); + cv::Mat result; + morphologyEx(img, result, cv::MORPH_DILATE, kernel); + + ASSERT_EQ(0, cvtest::norm(result, gold, NORM_INF)); +} }} // namespace -- 2.7.4