1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge pull request #28250 from satyam102006:fix/stackblur-overflow-28233

imgproc: fix heap-buffer-overflow in stackBlur #28233 #28250

### Summary
Fixes a heap-buffer-overflow in `cv::stackBlur` when the kernel size is larger than the image dimensions 
### Changes
* Added input validation to clamp the kernel size to the image dimensions.
* Added a regression test (`regression_28233`) covering 1x1 and small image cases.

Fixes #28233
This commit is contained in:
satyam yadav
2025-12-22 13:52:12 +05:30
committed by GitHub
parent a66443fdc2
commit 15fe69b5af
3 changed files with 23 additions and 4 deletions
+9 -3
View File
@@ -41,6 +41,7 @@ OTHER DEALINGS IN THE SOFTWARE.
#include "opencv2/core/hal/intrin.hpp"
#include <iostream>
#include <algorithm>
using namespace std;
@@ -1199,12 +1200,17 @@ void stackBlur(InputArray _src, OutputArray _dst, Size ksize)
CV_Assert( ksize.width > 0 && ksize.width % 2 == 1 &&
ksize.height > 0 && ksize.height % 2 == 1 );
int radiusH = ksize.height / 2;
int radiusW = ksize.width / 2;
int stype = _src.type(), sdepth = _src.depth();
Mat src = _src.getMat();
if (ksize.width > src.cols)
ksize.width = (src.cols % 2 == 0) ? std::max(1, src.cols - 1) : src.cols;
if (ksize.height > src.rows)
ksize.height = (src.rows % 2 == 0) ? std::max(1, src.rows - 1) : src.rows;
int radiusH = ksize.height / 2;
int radiusW = ksize.width / 2;
if (ksize.width == 1)
{
_src.copyTo(_dst);