mirror of
https://github.com/opencv/opencv.git
synced 2026-12-04 05:57:10 -06:00
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:
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user