From 2ceda58d80861c0d4110efb69f9559bbf140bce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E9=98=94=E8=B1=AA?= <2245258671@qq.com> Date: Tue, 19 May 2026 18:41:08 +0800 Subject: [PATCH] Merge pull request #29040 from MrBear999-ui:project4_MrBear imgproc: add kernel size validation in boxFilter #29040 Check that ksize dimensions are strictly positive in boxFilter(), returning StsBadSize error instead of producing undefined behavior. Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- modules/imgproc/src/box_filter.dispatch.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/imgproc/src/box_filter.dispatch.cpp b/modules/imgproc/src/box_filter.dispatch.cpp index 347cdc421e..1d23c72859 100644 --- a/modules/imgproc/src/box_filter.dispatch.cpp +++ b/modules/imgproc/src/box_filter.dispatch.cpp @@ -369,6 +369,7 @@ void boxFilter(InputArray _src, OutputArray _dst, int ddepth, CV_INSTRUMENT_REGION(); CV_Assert(!_src.empty()); + CV_Assert(ksize.width > 0 && ksize.height > 0); CV_OCL_RUN(_dst.isUMat() && (borderType == BORDER_REPLICATE || borderType == BORDER_CONSTANT ||