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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user