Merge pull request #31021 from sohailshk/fix/pyrup-empty-src

imgproc: do not crash in pyrUp on an empty source
This commit is contained in:
Abhishek Gola
2026-11-21 12:25:21 +05:30
committed by GitHub
2 changed files with 21 additions and 0 deletions

View File

@@ -1480,6 +1480,11 @@ void cv::pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int borderT
Size dsz = _dsz.empty() ? Size(src.cols*2, src.rows*2) : _dsz;
_dst.create( dsz, src.type() );
Mat dst = _dst.getMat();
if( src.empty() )
{
CV_Assert( dst.empty() );
return;
}
int depth = src.depth();
CALL_HAL(pyrUp, cv_hal_pyrup, src.data, src.step, src.cols, src.rows, dst.data, dst.step, dst.cols, dst.rows, depth, src.channels(), borderType);

View File

@@ -6,6 +6,22 @@
namespace opencv_test { namespace {
typedef testing::TestWithParam<Size> Imgproc_PyrUp_empty;
TEST_P(Imgproc_PyrUp_empty, no_crash)
{
Mat src(GetParam(), CV_8UC1), dst;
ASSERT_NO_THROW(pyrUp(src, dst));
EXPECT_TRUE(dst.empty());
// a non-empty destination size cannot be filled from an empty source
EXPECT_THROW(pyrUp(src, dst, Size(1, 10)), cv::Exception);
}
INSTANTIATE_TEST_CASE_P(/*nothing*/, Imgproc_PyrUp_empty, testing::Values(
Size(0, 0), Size(0, 5), Size(5, 0)
));
TEST(Imgproc_PyrUp, pyrUp_regression_22184)
{
Mat src(100,100,CV_16UC3,Scalar(255,255,255));